# Path: accounts/models.py
# class Team(models.Model, StatsFromChallengesMixin):
#     objects = TeamQuerySet.as_manager()
# 
#     name = models.CharField(max_length=256, unique=True)
#     users = models.ManyToManyField(User, through='accounts.userprofile')
#     created_at = models.DateTimeField(auto_now_add=True, editable=False)
#     created_by = models.ForeignKey(User, related_name='created_team', on_delete=models.CASCADE)
# 
#     @property
#     def num_users(self):
#         return self.users.count()
# 
#     @property
#     def challengesolved_set(self):
#         from challenges.models import ChallengeSolved
#         return ChallengeSolved.objects.filter(user__team=self)
# 
#     @property
#     def solved_challenges(self):
#         from challenges.models import Challenge
#         return Challenge.objects.filter(solved_by__team=self).distinct()
# 
#     @property
#     def failed_challenges(self):
#         from challenges.models import Challenge
#         return Challenge.objects\
#             .filter(failed_by__team=self)\
#             .distinct()\
#             .exclude(pk__in=self.solved_challenges.all())
# 
#     def __str__(self):
#         return self.name
# 
# class UserTeamRequest(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     team = models.ForeignKey(Team, on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now=True)
#     status = models.CharField(max_length=1, default='P', choices=(
#         ('P', 'Pending'),
#         ('A', 'Accepted'),
#         ('R', 'Rejected'),
#     ))
# 
#     objects = UserTeamRequestQuerySet.as_manager()
# 
#     def clean(self):
#         if not user_without_team(self.user):
#             raise ValidationError('User is already a team member')
# 
#         if self.status == 'P' and self.user.userteamrequest_set.filter(status='P').exists():
#             raise ValidationError('Other pending request exists')
# 
#         if self.status == 'P' and self.user.userteamrequest_set.filter(status='A').exists():
#             raise ValidationError('Other accepted request exists')
# 
# Path: challenges/models.py
# class ChallengeSolved(models.Model):
#     user = models.ForeignKey(RelatedUserModel, on_delete=models.CASCADE)
#     challenge = models.ForeignKey('challenges.Challenge', on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return 'Challenge: {}, User: {}'.format(self.challenge.name, self.user)


from rest_framework import serializers
from accounts.models import Team, UserTeamRequest
from challenges.models import ChallengeSolved



class ChallengeSolverSerializer(serializers.Serializer):
    challenge = serializers.IntegerField()
    key = serializers.CharField()

    def create(self, validated_data):
        pass


class ChallengeSolvedSerializer(serializers.ModelSerializer):

# Path: accounts/models.py
# class Team(models.Model, StatsFromChallengesMixin):
#     objects = TeamQuerySet.as_manager()
# 
#     name = models.CharField(max_length=256, unique=True)
#     users = models.ManyToManyField(User, through='accounts.userprofile')
#     created_at = models.DateTimeField(auto_now_add=True, editable=False)
#     created_by = models.ForeignKey(User, related_name='created_team', on_delete=models.CASCADE)
# 
#     @property
#     def num_users(self):
#         return self.users.count()
# 
#     @property
#     def challengesolved_set(self):
#         from challenges.models import ChallengeSolved
#         return ChallengeSolved.objects.filter(user__team=self)
# 
#     @property
#     def solved_challenges(self):
#         from challenges.models import Challenge
#         return Challenge.objects.filter(solved_by__team=self).distinct()
# 
#     @property
#     def failed_challenges(self):
#         from challenges.models import Challenge
#         return Challenge.objects\
#             .filter(failed_by__team=self)\
#             .distinct()\
#             .exclude(pk__in=self.solved_challenges.all())
# 
#     def __str__(self):
#         return self.name
# 
# class UserTeamRequest(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     team = models.ForeignKey(Team, on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now=True)
#     status = models.CharField(max_length=1, default='P', choices=(
#         ('P', 'Pending'),
#         ('A', 'Accepted'),
#         ('R', 'Rejected'),
#     ))
# 
#     objects = UserTeamRequestQuerySet.as_manager()
# 
#     def clean(self):
#         if not user_without_team(self.user):
#             raise ValidationError('User is already a team member')
# 
#         if self.status == 'P' and self.user.userteamrequest_set.filter(status='P').exists():
#             raise ValidationError('Other pending request exists')
# 
#         if self.status == 'P' and self.user.userteamrequest_set.filter(status='A').exists():
#             raise ValidationError('Other accepted request exists')
# 
# Path: challenges/models.py
# class ChallengeSolved(models.Model):
#     user = models.ForeignKey(RelatedUserModel, on_delete=models.CASCADE)
#     challenge = models.ForeignKey('challenges.Challenge', on_delete=models.CASCADE)
#     datetime = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return 'Challenge: {}, User: {}'.format(self.challenge.name, self.user)


# Path: challenges/serializers.py
from rest_framework import serializers
from accounts.models import Team, UserTeamRequest
from challenges.models import ChallengeSolved




class ChallengeSolverSerializer(serializers.Serializer):
    challenge = serializers.IntegerField()
    key = serializers.CharField()

    def create(self, validated_data):
        pass


class ChallengeSolvedSerializer(serializers.ModelSerializer):

    key = serializers.CharField()