from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

import apps.muestreo_laboratorio.models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("catalogos", "0001_initial"),
        ("recepciones", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ResultadoLaboratorio",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, editable=False)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "estado",
                    models.CharField(
                        choices=[
                            ("borrador", "Borrador"),
                            ("en_captura", "En captura"),
                            ("publicado", "Publicado"),
                        ],
                        default="borrador",
                        max_length=20,
                    ),
                ),
                (
                    "informe",
                    models.FileField(
                        blank=True,
                        null=True,
                        upload_to=apps.muestreo_laboratorio.models.informe_resultado_upload_path,
                    ),
                ),
                ("tags", models.JSONField(blank=True, default=list)),
                ("alertas", models.JSONField(blank=True, default=dict)),
                ("observaciones", models.TextField(blank=True)),
                ("fecha_publicacion", models.DateTimeField(blank=True, null=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "muestreo",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="resultado_laboratorio",
                        to="recepciones.muestreo",
                    ),
                ),
                (
                    "publicado_por",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="muestreo_laboratorio_resultados_publicados",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="TomaMuestra",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, editable=False)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("fecha_toma", models.DateTimeField(blank=True, null=True)),
                (
                    "latitud",
                    models.DecimalField(
                        blank=True, decimal_places=6, max_digits=9, null=True
                    ),
                ),
                (
                    "longitud",
                    models.DecimalField(
                        blank=True, decimal_places=6, max_digits=9, null=True
                    ),
                ),
                ("submuestras", models.JSONField(blank=True, default=list)),
                ("observaciones", models.TextField(blank=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "muestreo",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="toma_muestra",
                        to="recepciones.muestreo",
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ParametroResultado",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, editable=False)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "valor",
                    models.DecimalField(
                        blank=True, decimal_places=3, max_digits=10, null=True
                    ),
                ),
                ("unidad", models.CharField(blank=True, max_length=40)),
                ("observacion", models.TextField(blank=True)),
                ("fuera_de_rango", models.BooleanField(default=False)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "parametro",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="resultados_laboratorio",
                        to="catalogos.parametro",
                    ),
                ),
                (
                    "resultado_laboratorio",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="parametros",
                        to="muestreo_laboratorio.resultadolaboratorio",
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(app_label)s_%(class)s_updated",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "constraints": [
                    models.UniqueConstraint(
                        fields=("resultado_laboratorio", "parametro"),
                        name="uq_parametro_por_resultado_laboratorio",
                    )
                ]
            },
        ),
        migrations.CreateModel(
            name="FotoMuestra",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "tipo",
                    models.CharField(
                        choices=[
                            ("general", "General"),
                            ("sello", "Sello"),
                            ("muestra", "Muestra"),
                            ("otro", "Otro"),
                        ],
                        default="general",
                        max_length=20,
                    ),
                ),
                (
                    "imagen",
                    models.ImageField(
                        upload_to=apps.muestreo_laboratorio.models.foto_muestra_upload_path
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "toma_muestra",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="fotos",
                        to="muestreo_laboratorio.tomamuestra",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="FotoResultado",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "tipo",
                    models.CharField(
                        choices=[
                            ("general", "General"),
                            ("equipo", "Equipo"),
                            ("muestra", "Muestra"),
                            ("otro", "Otro"),
                        ],
                        default="general",
                        max_length=20,
                    ),
                ),
                (
                    "imagen",
                    models.ImageField(
                        upload_to=apps.muestreo_laboratorio.models.foto_resultado_upload_path
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "resultado_laboratorio",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="fotos",
                        to="muestreo_laboratorio.resultadolaboratorio",
                    ),
                ),
            ],
        ),
    ]
