# Path: bot/games/models.py
# class Game(models.Model):
#     name = models.CharField(_('name'), max_length=255)
#     alias_for = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
# 
#     objects = GameQuerySet.as_manager()
# 
#     class Meta:
#         verbose_name = _('game')
#         verbose_name_plural = _('games')
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self._old_alias_for_id = self.alias_for_id
# 
#     def clean(self):
#         if self.alias_for and self.alias_for.alias_for:
#             raise ValidationError(_("Aliases can only span one level"))
#         if self.alias_for and self.alias_for.name == self.name:
#             raise ValidationError(_("An alias must have a different name"))
# 
# Path: bot/users/models.py
# class Member(models.Model):
#     discord_id = models.CharField(max_length=50, unique=True)
#     name = models.CharField(_('name'), max_length=255)
#     last_seen = models.DateTimeField(null=True, blank=True)
# 
#     is_bot = models.BooleanField(default=False)
#     can_admin_bot = models.BooleanField(default=False)
# 
#     objects = MemberQuerySet.as_manager()
# 
#     def __str__(self):
#         return '<@{} name={}>'.format(self.discord_id, self.name)


from typing import Union
from django.db import models
from django.db.models import Count, Sum
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from bot.games.models import Game
from bot.users.models import Member
import discord




class LoggedMessage(models.Model):

    discord_id = models.BigIntegerField(unique=True)
    server = models.BigIntegerField(_("server"))

    member = models.ForeignKey('users.Member', related_name='messages_authored', on_delete=models.PROTECT)
    member_username = models.CharField(max_length=255)  # this can change, only the member.discord_id is a constant

    channel = models.ForeignKey('channels.Channel', on_delete=models.PROTECT)

    content = models.TextField()
    num_lines = models.PositiveSmallIntegerField(default=1)
    timestamp = models.DateTimeField(auto_now_add=True)
    edited_timestamp = models.DateTimeField(null=True, blank=True)

    mentions = models.ManyToManyField('users.Member', related_name='messages_mentioned_in', blank=True)

    class Meta:
        verbose_name = _('message')
        verbose_name_plural = _('messages')

# Path: bot/games/models.py
# class Game(models.Model):
#     name = models.CharField(_('name'), max_length=255)
#     alias_for = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
# 
#     objects = GameQuerySet.as_manager()
# 
#     class Meta:
#         verbose_name = _('game')
#         verbose_name_plural = _('games')
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self._old_alias_for_id = self.alias_for_id
# 
#     def clean(self):
#         if self.alias_for and self.alias_for.alias_for:
#             raise ValidationError(_("Aliases can only span one level"))
#         if self.alias_for and self.alias_for.name == self.name:
#             raise ValidationError(_("An alias must have a different name"))
# 
# Path: bot/users/models.py
# class Member(models.Model):
#     discord_id = models.CharField(max_length=50, unique=True)
#     name = models.CharField(_('name'), max_length=255)
#     last_seen = models.DateTimeField(null=True, blank=True)
# 
#     is_bot = models.BooleanField(default=False)
#     can_admin_bot = models.BooleanField(default=False)
# 
#     objects = MemberQuerySet.as_manager()
# 
#     def __str__(self):
#         return '<@{} name={}>'.format(self.discord_id, self.name)


# Path: bot/plugins/stats/models.py
from typing import Union
from django.db import models
from django.db.models import Count, Sum
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from bot.games.models import Game
from bot.users.models import Member
import discord





class LoggedMessage(models.Model):

    discord_id = models.BigIntegerField(unique=True)
    server = models.BigIntegerField(_("server"))

    member = models.ForeignKey('users.Member', related_name='messages_authored', on_delete=models.PROTECT)
    member_username = models.CharField(max_length=255)  # this can change, only the member.discord_id is a constant

    channel = models.ForeignKey('channels.Channel', on_delete=models.PROTECT)

    content = models.TextField()
    num_lines = models.PositiveSmallIntegerField(default=1)
    timestamp = models.DateTimeField(auto_now_add=True)
    edited_timestamp = models.DateTimeField(null=True, blank=True)

    mentions = models.ManyToManyField('users.Member', related_name='messages_mentioned_in', blank=True)

    class Meta:
        verbose_name = _('message')
        verbose_name_plural = _('messages')

        ordering = ['-timestamp']