# Generated by Django 6.0 on 2026-02-23 11:51

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


class Migration(migrations.Migration):
    dependencies = [
        ("endoreg_db", "0002_export_flags"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="PatientExaminationReport",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("template_name", models.CharField(max_length=255)),
                (
                    "template_version",
                    models.CharField(blank=True, default="", max_length=64),
                ),
                (
                    "template_hash",
                    models.CharField(blank=True, default="", max_length=128),
                ),
                ("title", models.CharField(blank=True, default="", max_length=255)),
                (
                    "status",
                    models.CharField(
                        choices=[("draft", "Draft"), ("final", "Final")],
                        default="draft",
                        max_length=16,
                    ),
                ),
                ("editor_payload", models.JSONField(blank=True, default=dict)),
                (
                    "patient_context_snapshot",
                    models.JSONField(blank=True, default=dict),
                ),
                (
                    "history_context_snapshot",
                    models.JSONField(blank=True, default=dict),
                ),
                ("rendered_text", models.TextField(blank=True, default="")),
                ("version", models.PositiveIntegerField(default=1)),
                ("is_active", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("finalized_at", models.DateTimeField(blank=True, null=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="created_patient_examination_reports",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "finalized_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="finalized_patient_examination_reports",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "patient_examination",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reports",
                        to="endoreg_db.patientexamination",
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="updated_patient_examination_reports",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-updated_at", "-id"],
            },
        ),
        migrations.AddIndex(
            model_name="patientexaminationreport",
            index=models.Index(
                fields=["patient_examination", "status"],
                name="endoreg_db__patient_8b8f6c_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="patientexaminationreport",
            index=models.Index(
                fields=["template_name", "status"],
                name="endoreg_db__templat_99ddab_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="patientexaminationreport",
            index=models.Index(
                fields=["updated_at"], name="endoreg_db__updated_dc6fb5_idx"
            ),
        ),
    ]
