# Path: users/models.py
# class Secretary (Employee, Observable):
#     is_superuser = False
#     activate =  models.BooleanField(default=False)
#     release_activate_at = models.DateTimeField(null=True, blank=True)
#     observers_in_secretary = []
# 
#     def listAllSecretaries(self):
#         secretaries = Secretary.objects.all()
#         return secretaries
# 
#     def add_observers(self):
#         self.observers_in_secretary = Administrator.objects.all()
#         
#     def remove_observers(self, input):
#         return
# 
#     def notify_observers(self, input):
#         for observer in self.observers_in_secretary:
#             observer.update(input)
# 
# 
#     def date_time_release(self):
#         date_now = datetime.now()
# 
#         if self.release_activate_at.date() == date_now.date():
#            if self.release_activate_at.hour - date_now.hour >= 6:
#                 self.add_observers()
#                 self.notify_observers(self.user.email) 
# 
#         else:
#             self.add_observers()
#             self.notify_observers(self.user.email)
# 
# class Administrator(Employee, Observer):
# 
#     is_superuser = True
# 
#     def register_employee(self,employee_type, name, phone_number, email, password):
#         if employee_type == 'secretary':
#             self.create_secretary(name, phone_number, email, password)
#         else:
#             self.create_administrator(name, phone_number, email, password)
# 
#     def remove_employee(self):
#         pass
# 
#     def release_login(self, id_Secretary):
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == False:
#                 secretary.activate = True
#                 secretary.release_activate_at = datetime.now()
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release                    
# 
# 
#     def block_login(self, id_Secretary):
# 
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == True:
#                 secretary.activate = False
#                 secretary.release_activate_at = None
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release
# 
#     def generate_superuser(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.is_superuser = True
#         user.save()
#         return user
# 
#     def generate_user(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.save()
#         return user
# 
#     def create_secretary(self, name, phone_number, email, password):
#         user = self.generate_user(self, name, email, password)
#         secretary = Secretary (user=user,
#                                phone_number=phone_number
#         )
#         secretary.save()
# 
#         return secretary
# 
#     def create_administrator(self, name, phone_number, email, password):
#         user = self.generate_superuser(self, name, email, password)
#         admin = Administrator (user=user,
#                               phone_number=phone_number
#         )
#         admin.save()
# 
#         return admin
# 
#     def update(self, input):
#         subject = "Login suspeito"
#         message = "O Secretario dolo do email: " + input + " realizou um login agora, este email eh informativo"
#         email_destination = self.user.email
#         email = Email()
#         email.send_email(subject, message, email_destination)
#         print(email_destination)


import factory
from users.models import Secretary, Administrator
from django.contrib.auth.models import User

class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model= User

    username = factory.Sequence(lambda n: 'username{0}'.format(n))
    first_name = factory.Sequence(lambda n: 'first_name{0}'.format(n))
    last_name = factory.Sequence(lambda n: 'last_name{0}'.format(n))
    email = factory.Sequence(lambda n: 'email{0}@gmail.com'.format(n))
    password = factory.PostGenerationMethodCall('set_password', 'test_password')



class SecretaryFactory(factory.DjangoModelFactory):
    class Meta:
        model= Secretary

    phone_number = factory.Sequence(lambda n: '{0}'.format(n))
    user = factory.SubFactory(UserFactory)

class AdministratorFactory(factory.DjangoModelFactory):

# Path: users/models.py
# class Secretary (Employee, Observable):
#     is_superuser = False
#     activate =  models.BooleanField(default=False)
#     release_activate_at = models.DateTimeField(null=True, blank=True)
#     observers_in_secretary = []
# 
#     def listAllSecretaries(self):
#         secretaries = Secretary.objects.all()
#         return secretaries
# 
#     def add_observers(self):
#         self.observers_in_secretary = Administrator.objects.all()
#         
#     def remove_observers(self, input):
#         return
# 
#     def notify_observers(self, input):
#         for observer in self.observers_in_secretary:
#             observer.update(input)
# 
# 
#     def date_time_release(self):
#         date_now = datetime.now()
# 
#         if self.release_activate_at.date() == date_now.date():
#            if self.release_activate_at.hour - date_now.hour >= 6:
#                 self.add_observers()
#                 self.notify_observers(self.user.email) 
# 
#         else:
#             self.add_observers()
#             self.notify_observers(self.user.email)
# 
# class Administrator(Employee, Observer):
# 
#     is_superuser = True
# 
#     def register_employee(self,employee_type, name, phone_number, email, password):
#         if employee_type == 'secretary':
#             self.create_secretary(name, phone_number, email, password)
#         else:
#             self.create_administrator(name, phone_number, email, password)
# 
#     def remove_employee(self):
#         pass
# 
#     def release_login(self, id_Secretary):
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == False:
#                 secretary.activate = True
#                 secretary.release_activate_at = datetime.now()
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release                    
# 
# 
#     def block_login(self, id_Secretary):
# 
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == True:
#                 secretary.activate = False
#                 secretary.release_activate_at = None
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release
# 
#     def generate_superuser(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.is_superuser = True
#         user.save()
#         return user
# 
#     def generate_user(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.save()
#         return user
# 
#     def create_secretary(self, name, phone_number, email, password):
#         user = self.generate_user(self, name, email, password)
#         secretary = Secretary (user=user,
#                                phone_number=phone_number
#         )
#         secretary.save()
# 
#         return secretary
# 
#     def create_administrator(self, name, phone_number, email, password):
#         user = self.generate_superuser(self, name, email, password)
#         admin = Administrator (user=user,
#                               phone_number=phone_number
#         )
#         admin.save()
# 
#         return admin
# 
#     def update(self, input):
#         subject = "Login suspeito"
#         message = "O Secretario dolo do email: " + input + " realizou um login agora, este email eh informativo"
#         email_destination = self.user.email
#         email = Email()
#         email.send_email(subject, message, email_destination)
#         print(email_destination)


# Path: users/tests/factories.py
import factory
from users.models import Secretary, Administrator
from django.contrib.auth.models import User


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model= User

    username = factory.Sequence(lambda n: 'username{0}'.format(n))
    first_name = factory.Sequence(lambda n: 'first_name{0}'.format(n))
    last_name = factory.Sequence(lambda n: 'last_name{0}'.format(n))
    email = factory.Sequence(lambda n: 'email{0}@gmail.com'.format(n))
    password = factory.PostGenerationMethodCall('set_password', 'test_password')



class SecretaryFactory(factory.DjangoModelFactory):
    class Meta:
        model= Secretary

    phone_number = factory.Sequence(lambda n: '{0}'.format(n))
    user = factory.SubFactory(UserFactory)

class AdministratorFactory(factory.DjangoModelFactory):

    class Meta: