import datetime

from django.contrib.auth.models import User
from django.db import models

# Create your models here.

class Personales(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.CASCADE)
    l_nacimiento=models.CharField(max_length=60,null=True,blank=True)
    f_nacimiento=models.DateField(null=True,blank=True)
    edad=models.IntegerField(default=0)
    genero=models.CharField(max_length=60,null=True,blank=True)
    etnia=models.CharField(max_length=60,null=True,blank=True)
    e_civil=models.CharField(max_length=60,null=True,blank=True)
    nacionalidad=models.CharField(max_length=60,null=True,blank=True)

    celular=models.CharField(max_length=10,null=True,blank=True)
    telefono=models.CharField(max_length=10,null=True,blank=True)
    correo_p=models.EmailField(max_length=100,null=True,blank=True)
    correo_i=models.EmailField(max_length=100,null=True,blank=True)

    lugar=models.CharField(max_length=60,null=True,blank=True)
    provincia=models.CharField(max_length=60,null=True,blank=True)
    canton=models.CharField(max_length=60,null=True,blank=True)
    parroquia=models.CharField(max_length=60,null=True,blank=True)
    barrio=models.CharField(max_length=100,null=True,blank=True)
    calle_principal=models.CharField(max_length=100,null=True,blank=True)
    calle_secundaria=models.CharField(max_length=100,null=True,blank=True)
    numero_casa=models.CharField(max_length=100,null=True,blank=True)
    referencia=models.CharField(max_length=100,null=True,blank=True)

    nombre_contacto=models.CharField(max_length=60,null=True,blank=True)
    parentesco=models.CharField(max_length=60,null=True,blank=True)
    cedula_contacto=models.CharField(max_length=10,null=True,blank=True)
    celular_contacto=models.CharField(max_length=10,null=True,blank=True)
    convencional_contacto=models.CharField(max_length=10,null=True,blank=True)
    direccion=models.CharField(max_length=100,null=True,blank=True)

    titulo=models.CharField(max_length=100,null=True,blank=True)
    pais=models.CharField(max_length=100,null=True,blank=True)
    area=models.CharField(max_length=100,null=True,blank=True)
    institucion_educativa=models.CharField(max_length=100,null=True,blank=True)
    numero_periodos=models.IntegerField(default=0)
    tipo_periodo=models.CharField(max_length=100,null=True,blank=True)
    egresado=models.CharField(max_length=100,null=True,blank=True)
    numero_registro=models.CharField(max_length=100,null=True,blank=True)

    tipo_sangre=models.CharField(max_length=60,null=True,blank=True)
    discapacidad=models.CharField(max_length=2, help_text="Si/No",null=True,blank=True)
    tipo_discapacidad=models.CharField(max_length=60,null=True,blank=True)
    porcentaje_discapacidad=models.IntegerField(default=0)
    carnet_CONADIS=models.CharField(max_length=60,null=True,blank=True)
    sustituto=models.CharField(max_length=2, help_text="Si/No",null=True,blank=True)
    fecha_declaracion=models.DateField(null=True,blank=True)
    nombres_familiar=models.CharField(max_length=60,null=True,blank=True)
    telefono_sustituto=models.CharField(max_length=10,null=True,blank=True)
    t_enfermedad_sustituto=models.CharField(max_length=10,null=True,blank=True)
    enfermedad_sustituto=models.CharField(max_length=60,null=True,blank=True)


    ingreso_institucion=models.DateField(null=True,blank=True)
    tiempo_servicio=models.IntegerField(default=0)
    ultima_fecha_entrada_servicio_publico=models.DateField(null=True,blank=True)
    ultimo_tiempo_servicio_anios=models.IntegerField(default=0)
    ultimo_tiempo_servicio_meses = models.IntegerField(default=0)
    finalizacion_contrato=models.DateField(null=True,blank=True)
    estado=models.BooleanField(default=True)

    acumulacion=models.BooleanField(default=True)
    cuenta_bancaria=models.IntegerField(default=0)
    banco=models.CharField(max_length=60,null=True,blank=True)
    tipo_cuenta=models.CharField(max_length=60,null=True,blank=True)

    solicitud=models.CharField(max_length=60,null=True,blank=True)
    fecha_entrega=models.DateField(null=True,blank=True)
    informe_tecnico=models.CharField(max_length=60,null=True,blank=True)
    completado=models.DateField(null=True,blank=True)
    firma=models.DateField(null=True,blank=True)
    servidor=models.CharField(max_length=60,null=True,blank=True, default="ABG. ADRIANA RIVAS")
    finanzas=models.CharField(max_length=60,null=True,blank=True)
    archivo=models.CharField(max_length=200,null=True,blank=True)
    numero_meses=models.IntegerField(default=0)
    remuneracion=models.DecimalField(max_digits=9, decimal_places=2, default=0)

    def save(
        self, force_insert=False, force_update=False, using=None, update_fields=None
    ):

        if self.f_nacimiento:
            fecha = datetime.datetime.strptime(str(self.f_nacimiento), '%Y-%m-%d')
            self.edad=datetime.datetime.now().year-fecha.date().year

        if self.finalizacion_contrato:
            fecha = datetime.datetime.strptime(str(self.f_nacimiento), '%Y-%m-%d')
            if fecha.year>datetime.datetime.now().year:
                self.estado="A"
            else:
                self.estado=False

        super(Personales,self).save()

class Licencias(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.CASCADE)
    tipo=models.CharField(max_length=3)
    f_caducidad=models.DateField()
    estado=models.BooleanField(default=True)

    def save(
        self, force_insert=False, force_update=False, using=None, update_fields=None
    ):
        fecha=datetime.datetime.strptime(str(self.f_caducidad),'%Y-%m-%d')
        fecha2 = datetime.datetime(datetime.datetime.now().year,datetime.datetime.now().month,datetime.datetime.now().day)
        if fecha > fecha2:
            self.estado=True
        else:
            self.estado=False
        super(Licencias,self).save()

class Enfermedades(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.CASCADE)
    catastrofica=models.BooleanField(default=False)
    enfermedad=models.CharField(max_length=60)

class Capacitacion(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.CASCADE, null=True,blank=True)
    evento=models.CharField(max_length=120)
    tipo=models.CharField(max_length=60)
    duracion=models.IntegerField(default=0)
    auspiciante=models.CharField(max_length=60)
    tipo_certificado=models.CharField(max_length=60)
    certificado_por=models.CharField(max_length=60)
    fecha_inicio=models.DateField(null=True,blank=True)
    fecha_finalizacion=models.DateField(null=True,blank=True)
    pais=models.CharField(max_length=60, default="Ecuador")

class TrayectoriaLaboral(models.Model):
    usuario=models.ForeignKey(User,on_delete=models.CASCADE)
    tipo_insititucion=models.CharField(max_length=60)
    fecha_ingreso=models.DateField(null=True,blank=True)
    nombre_insitutucion=models.CharField(max_length=100)
    unidad_administrativa=models.CharField(max_length=100, default=" ")
    puesto=models.CharField(max_length=60)
    fecha_salida=models.DateField(null=True,blank=True)
    motivo_ingreso=models.CharField(max_length=60, default=" ")
    motivo_salida=models.CharField(max_length=60, default=" ")

class Vivienda(models.Model):
    usuario=models.ForeignKey(User,on_delete=models.CASCADE)
    tipo_relacion=models.CharField(max_length=60, null=True,blank=True)
    tipo_documento=models.CharField(max_length=60, null=True,blank=True)
    numero_documento=models.CharField(max_length=10, null=True,blank=True)
    nombres=models.CharField(max_length=60, null=True,blank=True)
    fecha_nacimiento=models.DateField(null=True, blank=True)
    edad=models.IntegerField(default=0)
    estado_civil=models.CharField(max_length=60, null=True,blank=True)
    instruccion_formal=models.CharField(max_length=60, null=True,blank=True)
    profesion=models.CharField(max_length=60, null=True,blank=True)
    institucion_labora=models.CharField(max_length=60, null=True,blank=True)
    tipo_institucion=models.CharField(max_length=60, null=True,blank=True)
    ingreso_mensual=models.CharField(max_length=60, null=True,blank=True)
    discapacidad=models.CharField(max_length=60, null=True,blank=True)
    tipo_discapacidad=models.CharField(max_length=60, null=True,blank=True)
    porcentaje_discapacidad=models.CharField(max_length=60, null=True,blank=True)
    carnet_conadis=models.CharField(max_length=60, null=True,blank=True)
    enfermedad=models.CharField(max_length=60, null=True,blank=True)
    tipo_enfermedad=models.CharField(max_length=60, null=True,blank=True)
    tipo_sangre=models.CharField(max_length=60, null=True,blank=True)
    vive_con_usted=models.CharField(max_length=60, null=True,blank=True)

class CondicionesVida(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.CASCADE)
    agua=models.BooleanField(default=True)
    alumbrado_vivienda=models.BooleanField(default=True)
    alumbrado_publico=models.BooleanField(default=True)
    alcantarillado=models.BooleanField(default=True)
    calles=models.BooleanField(default=True)
    basura=models.BooleanField(default=True)
    iglesia=models.BooleanField(default=True)
    hospital=models.BooleanField(default=True)
    centro_medico=models.BooleanField(default=True)
    subcentro=models.BooleanField(default=True)
    escuela=models.BooleanField(default=True)
    colegio=models.BooleanField(default=True)
    mercado=models.BooleanField(default=True)
    telefono_convencional=models.BooleanField(default=True)
    telefono_celular=models.BooleanField(default=True)
    internet=models.BooleanField(default=True)
    transporte=models.BooleanField(default=True)
    seguridad=models.BooleanField(default=True)
    estado_calles=models.BooleanField(default=True)
    aceras=models.BooleanField(default=True)
    bordillos=models.BooleanField(default=True)
    colector_aguas_lluvias=models.BooleanField(default=True)
    otros=models.CharField(max_length=60)
    tenencia_vivienda=models.BooleanField(default=True)
    tipo_vivienda=models.CharField(max_length=60)
    tipo_familia=models.CharField(max_length=60)
    dormitorios=models.BooleanField(default=True)
    sala=models.BooleanField(default=True)
    comedor=models.BooleanField(default=True)
    sala_comedor=models.BooleanField(default=True)
    cocina=models.BooleanField(default=True)
    banios=models.BooleanField(default=True)
    patio=models.BooleanField(default=True)
    garaje=models.BooleanField(default=True)
    otros_c=models.CharField(max_length=60)
    potable=models.BooleanField(default=True)
    hervida=models.BooleanField(default=True)
    tratada=models.BooleanField(default=True)
    cisterna=models.BooleanField(default=True)
    pozo=models.BooleanField(default=True)
    tanqueros=models.BooleanField(default=True)
    otro_a=models.CharField(max_length=60)
    alimentacion=models.BooleanField(default=True)
    recolector_basura=models.BooleanField(default=True)
    quma_basura=models.BooleanField(default=True)
    otro_b=models.CharField(max_length=60)

class InformacionMonetaria(models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE,null=True,blank=True)
    vivienda=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    manutencion=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    educacion=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    medicina=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    alimentacion=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    vestuario=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    extraordinario=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    total=models.DecimalField(decimal_places=2, max_digits=9, default=0)
    ahorro=models.DecimalField(decimal_places=2, max_digits=9, default=0)

class EnfermedadesAccidentes(models.Model):
    usuario=models.ForeignKey(User, on_delete=models.Model)
    enfermedades=models.BooleanField(default=False)
    enfermedades_hereditarias=models.CharField(max_length=60)
    accidente=models.BooleanField(default=False)
    tipo_accidente=models.CharField(max_length=60)
    consecuencia=models.CharField(max_length=60)
    hospital_publico=models.BooleanField(default=False)
    hospital_IESS=models.BooleanField(default=False)
    clinica=models.BooleanField(default=False)
    centro_salud=models.BooleanField(default=False)
    medico_particular=models.BooleanField(default=False)
    otro=models.CharField(max_length=60)

class ApoyoEconomico(models.Model):
    usuario=models.ForeignKey(User,on_delete=models.CASCADE,null=True,blank=True)
    padres=models.BooleanField(default=False)
    hijo=models.BooleanField(default=False)
    conyuge=models.BooleanField(default=False)
    otro=models.BooleanField(default=False)

class InformacionSocial(models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    servidor=models.BooleanField(default=False)
    conyuge=models.BooleanField(default=False)
    familiares=models.BooleanField(default=False)
    guarderias=models.BooleanField(default=False)
    empleada_domestica=models.BooleanField(default=False)
    niniera=models.BooleanField(default=False)
    vecinos=models.BooleanField(default=False)
    otros=models.BooleanField(default=False)
    leer=models.BooleanField(default=False)
    escuchar_musica=models.BooleanField(default=False)
    deportes=models.BooleanField(default=False)
    reuniones=models.BooleanField(default=False)
    quehaceres=models.BooleanField(default=False)
    trabajos_extras=models.BooleanField(default=False)
    otro=models.BooleanField(default=False)


