from django.conf.global_settings import STATIC_ROOT
from django.contrib.postgres.fields import ArrayField
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
from django.utils import timezone

class Formulario(models.Model):
    id = models.AutoField(primary_key=True)
    admin = models.CharField(max_length=150, null=False)
    titulo = models.TextField()
    numSecciones = models.IntegerField(null=False, default=0)
    numRespuestas = models.IntegerField(null=False, default=0)

    class Meta:
        def __unicode__(self):
            return self.id

class PaginaPrincipal(models.Model):
    id = models.AutoField(primary_key=True)
    formulario = models.OneToOneField(Formulario, on_delete=models.CASCADE)
    titulo = models.TextField()
    subtitulo = models.TextField(null=True)
    cuerpo = models.TextField()

    class Meta:
        verbose_name_plural = "PaginesPrincipals"
        def __unicode__(self):
            return self.titulo

class DatosPersonales(models.Model):
    id = models.AutoField(primary_key=True)
    formulario = models.OneToOneField(Formulario, on_delete=models.CASCADE)
    numDatos = models.IntegerField(null=False, default=0)
    class Meta:
        def __unicode__(self):
            return self.id

class Usuario(models.Model):
    id = models.AutoField(primary_key=True)
    numDatos = models.IntegerField(null=True, default=0)
    date = models.DateField(default=timezone.now)

    class Meta:
        def __unicode__(self):
            return self.id

class Informacion(models.Model):
    id = models.AutoField(primary_key=True)
    datosPersonales = models.ForeignKey(DatosPersonales, on_delete=models.CASCADE)
    tipo = models.CharField(max_length=50, null=False)
    pregunta = models.TextField()
    posicion = models.IntegerField(null=False, default=0)
    class Meta:
        def __unicode__(self):
            return self.id


class RespuestaInfo(models.Model):
    id = models.AutoField(primary_key=True)
    informacion = models.ForeignKey(Informacion, on_delete=models.CASCADE)
    usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE)
    respuesta = models.TextField()

    class Meta:
        def __unicode__(self):
            return self.id

fs = FileSystemStorage(location='/static/images')

class Seccion(models.Model):
    id = models.AutoField(primary_key=True)
    formulario = models.ForeignKey(Formulario, on_delete=models.CASCADE)
    tipoContexto = models.CharField(max_length=10, null=False)
    texto = models.TextField(null=True)
    audio = models.CharField(max_length=100, null=False)
    imagen = models.CharField(max_length=100, null=True)
    posicion = models.IntegerField(null=False, default=0)
    class Meta:
        def __unicode__(self):
            return self.id


class Respuesta(models.Model):
    id = models.AutoField(primary_key=True)
    seccion = models.ForeignKey(Seccion, on_delete=models.CASCADE)
    audio = models.CharField(max_length=100, null=False)
    usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE)
    class Meta:
        def __unicode__(self):
            return self.id




