# 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.rides.models.media


class Migration(migrations.Migration):
    dependencies = [
        ("pghistory", "0006_delete_aggregateevent"),
        ("rides", "0006_add_ride_rankings"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="RidePhoto",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "image",
                    models.ImageField(
                        max_length=255,
                        upload_to=apps.rides.models.media.ride_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)),
                (
                    "photo_type",
                    models.CharField(
                        choices=[
                            ("exterior", "Exterior View"),
                            ("queue", "Queue Area"),
                            ("station", "Station"),
                            ("onride", "On-Ride"),
                            ("construction", "Construction"),
                            ("other", "Other"),
                        ],
                        default="exterior",
                        max_length=50,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("date_taken", models.DateTimeField(blank=True, null=True)),
                (
                    "ride",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="photos",
                        to="rides.ride",
                    ),
                ),
                (
                    "uploaded_by",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="uploaded_ride_photos",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-is_primary", "-created_at"],
            },
        ),
        migrations.CreateModel(
            name="RidePhotoEvent",
            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.rides.models.media.ride_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)),
                (
                    "photo_type",
                    models.CharField(
                        choices=[
                            ("exterior", "Exterior View"),
                            ("queue", "Queue Area"),
                            ("station", "Station"),
                            ("onride", "On-Ride"),
                            ("construction", "Construction"),
                            ("other", "Other"),
                        ],
                        default="exterior",
                        max_length=50,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("date_taken", models.DateTimeField(blank=True, null=True)),
                (
                    "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="rides.ridephoto",
                    ),
                ),
                (
                    "ride",
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to="rides.ride",
                    ),
                ),
                (
                    "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="ridephoto",
            index=models.Index(fields=["ride", "is_primary"], name="rides_ridep_ride_id_aa49f1_idx"),
        ),
        migrations.AddIndex(
            model_name="ridephoto",
            index=models.Index(fields=["ride", "is_approved"], name="rides_ridep_ride_id_f1eddc_idx"),
        ),
        migrations.AddIndex(
            model_name="ridephoto",
            index=models.Index(fields=["ride", "photo_type"], name="rides_ridep_ride_id_49e7ec_idx"),
        ),
        migrations.AddIndex(
            model_name="ridephoto",
            index=models.Index(fields=["created_at"], name="rides_ridep_created_106e02_idx"),
        ),
        migrations.AddConstraint(
            model_name="ridephoto",
            constraint=models.UniqueConstraint(
                condition=models.Q(("is_primary", True)),
                fields=("ride",),
                name="unique_primary_ride_photo",
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="ridephoto",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "rides_ridephotoevent" ("alt_text", "caption", "created_at", "date_taken", "id", "image", "is_approved", "is_primary", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "photo_type", "ride_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", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."photo_type", NEW."ride_id", NEW."updated_at", NEW."uploaded_by_id"); RETURN NULL;',
                    hash="8027f17cac76b8301927e468ab4873ae9f38f27a",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_0043a",
                    table="rides_ridephoto",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="ridephoto",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "rides_ridephotoevent" ("alt_text", "caption", "created_at", "date_taken", "id", "image", "is_approved", "is_primary", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "photo_type", "ride_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", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."photo_type", NEW."ride_id", NEW."updated_at", NEW."uploaded_by_id"); RETURN NULL;',
                    hash="54562f9a78754cac359f1efd5c0e8d6d144d1806",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_93a7e",
                    table="rides_ridephoto",
                    when="AFTER",
                ),
            ),
        ),
    ]
