from django.db import models

class Networks(models.Model):
    name = models.CharField(unique=True, max_length=40)
    host = models.CharField(unique=True, max_length=60)
    port = models.IntegerField(blank=True, null=True)
    use_ssl = models.NullBooleanField()
    nickname = models.CharField(max_length=31, blank=True, null=True)
    username = models.CharField(max_length=31, blank=True, null=True)
    password = models.CharField(max_length=31, blank=True, null=True)
    home_channel = models.CharField(max_length=64)
    command_character = models.CharField(max_length=1, blank=True, null=True)
    help_character = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'networks'
    
    def __str__(self):
        return self.name

class Channels(models.Model):
    name = models.CharField(max_length=64)
    network = models.ForeignKey('Networks', models.DO_NOTHING, to_field='name', db_column='network')
    autojoin = models.NullBooleanField()
    join_greeting = models.NullBooleanField()
    statistics_commands = models.NullBooleanField()
    games = models.NullBooleanField()
    aggressiveness = models.CharField(max_length=20, blank=True, null=True)
    chat = models.NullBooleanField()
    key = models.CharField(max_length=32, blank=True, null=True)
    last_lame = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'channels'
        unique_together = (('name', 'network'),)
    
    def __str__(self):
        return self.name

class Users(models.Model):
    name = models.CharField(max_length=31)
    network = models.ForeignKey(Networks, models.DO_NOTHING, to_field='name', db_column='network')
    last_act_type = models.CharField(max_length=20, blank=True, null=True)
    last_act_datetime = models.DateTimeField(blank=True, null=True)
    last_act_channel = models.ForeignKey(Channels, models.DO_NOTHING, db_column='last_act_channel', blank=True, null=True)
    last_act_channel_network = models.CharField(max_length=40, blank=True, null=True)
    last_act = models.CharField(max_length=510, blank=True, null=True)
    last_act_auxiliary = models.CharField(max_length=255, blank=True, null=True)
    away = models.NullBooleanField()
    away_reason = models.CharField(max_length=510, blank=True, null=True)
    xp_spent = models.IntegerField(blank=True, null=True)
    level = models.IntegerField(blank=True, null=True)
    coin = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    coin_spent = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    coin_given = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    ap_spent = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'users'
        unique_together = (('name', 'network'),)
    
    def __str__(self):
        return self.name

class Joins(models.Model):
    channel = models.ForeignKey(Channels, models.DO_NOTHING, db_column='channel')
    channel_network = models.CharField(max_length=40)
    user = models.ForeignKey('Users', models.DO_NOTHING, db_column='user')
    user_network = models.CharField(max_length=40)
    joins = models.IntegerField(blank=True, null=True)
    stopgreet = models.NullBooleanField()

    class Meta:
        managed = False
        db_table = 'joins'
        unique_together = (('channel', 'channel_network', 'user', 'user_network'),)
    
    def __str__(self):
        return self.channel_network + "_" + self.channel + "_" + self.user

class Kicks(models.Model):
    channel = models.ForeignKey(Channels, models.DO_NOTHING, db_column='channel')
    channel_network = models.CharField(max_length=40)
    user = models.ForeignKey('Users', models.DO_NOTHING, db_column='user')
    user_network = models.CharField(max_length=40)
    given = models.IntegerField(blank=True, null=True)
    received = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'kicks'
        unique_together = (('channel', 'channel_network', 'user', 'user_network'),)
    
    def __str__(self):
        return self.channel_network + "_" + self.channel + "_" + self.user

class Messages(models.Model):
    channel = models.ForeignKey(Channels, models.DO_NOTHING, db_column='channel')
    channel_network = models.CharField(max_length=40)
    user = models.ForeignKey('Users', models.DO_NOTHING, db_column='user')
    user_network = models.CharField(max_length=40)
    messages = models.IntegerField(blank=True, null=True)
    messages_words = models.BigIntegerField(blank=True, null=True)
    messages_characters = models.BigIntegerField(blank=True, null=True)
    actions = models.IntegerField(blank=True, null=True)
    actions_words = models.BigIntegerField(blank=True, null=True)
    actions_characters = models.BigIntegerField(blank=True, null=True)
    notices = models.IntegerField(blank=True, null=True)
    notices_words = models.BigIntegerField(blank=True, null=True)
    notices_characters = models.BigIntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'messages'
        unique_together = (('channel', 'channel_network', 'user', 'user_network'),)
    
    def __str__(self):
        return self.channel_network + "_" + self.channel + "_" + self.user
