# Generated by Django 5.2.5 on 2025-08-26 17:39

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

import apps.parks.models.media


class Migration(migrations.Migration):
    dependencies = [
        ("parks", "0007_companyheadquartersevent_parklocationevent_and_more"),
        ("pghistory", "0006_delete_aggregateevent"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ParkPhoto",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "image",
                    models.ImageField(
                        max_length=255,
                        upload_to=apps.parks.models.media.park_photo_upload_path,
                    ),
                ),
                ("caption", models.CharField(blank=True, max_length=255)),
                ("alt_text", models.CharField(blank=True, max_length=255)),
                ("is_primary", models.BooleanField(default=False)),
                ("is_approved", models.BooleanField(default=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("date_taken", models.DateTimeField(blank=True, null=True)),
                (
                    "park",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="photos",
                        to="parks.park",
                    ),
                ),
                (
                    "uploaded_by",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="uploaded_park_photos",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-is_primary", "-created_at"],
            },
        ),
        migrations.CreateModel(
            name="ParkPhotoEvent",
            fields=[
                ("pgh_id", models.AutoField(primary_key=True, serialize=False)),
                ("pgh_created_at", models.DateTimeField(auto_now_add=True)),
                ("pgh_label", models.TextField(help_text="The event label.")),
                ("id", models.BigIntegerField()),
                (
                    "image",
                    models.ImageField(
                        max_length=255,
                        upload_to=apps.parks.models.media.park_photo_upload_path,
                    ),
                ),
                ("caption", models.CharField(blank=True, max_length=255)),
                ("alt_text", models.CharField(blank=True, max_length=255)),
                ("is_primary", models.BooleanField(default=False)),
                ("is_approved", models.BooleanField(default=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("date_taken", models.DateTimeField(blank=True, null=True)),
                (
                    "park",
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to="parks.park",
                    ),
                ),
                (
                    "pgh_context",
                    models.ForeignKey(
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="pghistory.context",
                    ),
                ),
                (
                    "pgh_obj",
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="events",
                        to="parks.parkphoto",
                    ),
                ),
                (
                    "uploaded_by",
                    models.ForeignKey(
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddIndex(
            model_name="parkphoto",
            index=models.Index(fields=["park", "is_primary"], name="parks_parkp_park_id_eda26e_idx"),
        ),
        migrations.AddIndex(
            model_name="parkphoto",
            index=models.Index(fields=["park", "is_approved"], name="parks_parkp_park_id_5fe576_idx"),
        ),
        migrations.AddIndex(
            model_name="parkphoto",
            index=models.Index(fields=["created_at"], name="parks_parkp_created_033dc3_idx"),
        ),
        migrations.AddConstraint(
            model_name="parkphoto",
            constraint=models.UniqueConstraint(
                condition=models.Q(("is_primary", True)),
                fields=("park",),
                name="unique_primary_park_photo",
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkphoto",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "parks_parkphotoevent" ("alt_text", "caption", "created_at", "date_taken", "id", "image", "is_approved", "is_primary", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at", "uploaded_by_id") VALUES (NEW."alt_text", NEW."caption", NEW."created_at", NEW."date_taken", NEW."id", NEW."image", NEW."is_approved", NEW."is_primary", NEW."park_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."updated_at", NEW."uploaded_by_id"); RETURN NULL;',
                    hash="eeeb8afb335eb66cb4550a0f5abfaf7280472827",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_e2033",
                    table="parks_parkphoto",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkphoto",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "parks_parkphotoevent" ("alt_text", "caption", "created_at", "date_taken", "id", "image", "is_approved", "is_primary", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at", "uploaded_by_id") VALUES (NEW."alt_text", NEW."caption", NEW."created_at", NEW."date_taken", NEW."id", NEW."image", NEW."is_approved", NEW."is_primary", NEW."park_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."updated_at", NEW."uploaded_by_id"); RETURN NULL;',
                    hash="bd95069068ba9e1a78708a0a9cc73d6507fab691",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_42711",
                    table="parks_parkphoto",
                    when="AFTER",
                ),
            ),
        ),
    ]
