#from django.contrib.auth.models import BaseUserManager
from django.contrib.auth.models import User
from django.db import models

class ExecUserManager(models.Manager):
    def create_exec(self, username, email, password, season, year):
        user = User.objects.create_user(username, email, password)
        user.save()
        exec_user = self.model(user=user)
        exec_user.save()
        SemesterManager.create_semester(exec_user, season, year)
        return exec_user

class SiteAdminUserManager(models.Manager):
    def create_site_admin(self, username, email, password,is_staff, is_superuser, season, year):
        user = User.objects.create_user(username, email, password)
        user.save()
        site_admin = self.model(user=user)
        site_admin.save()
        return site_admin

class DirectorUserManager(models.Manager):
    def create_director(self, username, email, password, team):
        user = User.objects.create_user(username, email, password)
        user.save()
        director = self.model(user = user, team = team)
        director.save()
        return director

class SemesterManager(models.Manager):
    def create_semester(self, afx_exec, season, year):
        semester = self.model(afx_exec=afx_exec, season=season, year=year)
        semester.save()
        return semester
    def dancer_exists(self, email):
      c = self.dancers.filter(semester=self, email=email).count()
      return (c > 0)

class DancerManager(models.Manager):
    def checkAll(self, semester):
        c = self.filter(semester=semester, check_dancer=False).count()
        return (c > 0)
    def create_dancer(self, semester, phone, email, name, gender):
        d = self.model(semester=semester,phone=phone,email=email,name=name,gender=gender)
        d.save()
        return d

class CastingGroupManager(models.Manager):
    def create_casting_group(self, semester, dancers):
        cg = self.model(semester=semester)
        cg.save()
        for d in dancers:
            d.casting_group = cg
            d.save()
        return cg

class TeamManager(models.Manager):
    def create_team(self, level, name, semester):
        if level=='T':
            t = self.model(size_limit=15, locked=True,level=level, name=name, semester=semester)
        elif level == 'P':
            t = self.model(size_limit=float('inf'),locked=False,level=level, name=name, semester=semester)
        t.save()
        return t









