# Generated by Django 5.2.5 on 2025-08-15 22:01

import django.contrib.gis.db.models.fields
import django.contrib.postgres.fields
import django.core.validators
import django.db.models.deletion
import pgtrigger.compiler
import pgtrigger.migrations
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("pghistory", "0006_delete_aggregateevent"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Company",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(max_length=255, unique=True)),
                (
                    "roles",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(
                            choices=[
                                ("OPERATOR", "Park Operator"),
                                ("PROPERTY_OWNER", "Property Owner"),
                            ],
                            max_length=20,
                        ),
                        blank=True,
                        default=list,
                        size=None,
                    ),
                ),
                ("description", models.TextField(blank=True)),
                ("website", models.URLField(blank=True)),
                (
                    "founded_year",
                    models.PositiveIntegerField(blank=True, null=True),
                ),
                ("parks_count", models.IntegerField(default=0)),
                ("rides_count", models.IntegerField(default=0)),
            ],
            options={
                "verbose_name_plural": "Companies",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="Park",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(max_length=255, unique=True)),
                ("description", models.TextField(blank=True)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("OPERATING", "Operating"),
                            ("CLOSED_TEMP", "Temporarily Closed"),
                            ("CLOSED_PERM", "Permanently Closed"),
                            ("UNDER_CONSTRUCTION", "Under Construction"),
                            ("DEMOLISHED", "Demolished"),
                            ("RELOCATED", "Relocated"),
                        ],
                        default="OPERATING",
                        max_length=20,
                    ),
                ),
                ("opening_date", models.DateField(blank=True, null=True)),
                ("closing_date", models.DateField(blank=True, null=True)),
                (
                    "operating_season",
                    models.CharField(blank=True, max_length=255),
                ),
                (
                    "size_acres",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True),
                ),
                ("website", models.URLField(blank=True)),
                (
                    "average_rating",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=3, null=True),
                ),
                ("ride_count", models.IntegerField(blank=True, null=True)),
                ("coaster_count", models.IntegerField(blank=True, null=True)),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, null=True),
                ),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "operator",
                    models.ForeignKey(
                        help_text="Company that operates this park",
                        limit_choices_to={"roles__contains": ["OPERATOR"]},
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="operated_parks",
                        to="parks.company",
                    ),
                ),
                (
                    "property_owner",
                    models.ForeignKey(
                        blank=True,
                        help_text="Company that owns the property (if different from operator)",
                        limit_choices_to={"roles__contains": ["PROPERTY_OWNER"]},
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="owned_parks",
                        to="parks.company",
                    ),
                ),
            ],
            options={
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="ParkArea",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(max_length=255)),
                ("description", models.TextField(blank=True)),
                ("opening_date", models.DateField(blank=True, null=True)),
                ("closing_date", models.DateField(blank=True, null=True)),
                (
                    "park",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="areas",
                        to="parks.park",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="ParkAreaEvent",
            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()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(db_index=False, max_length=255)),
                ("description", models.TextField(blank=True)),
                ("opening_date", models.DateField(blank=True, null=True)),
                ("closing_date", models.DateField(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.parkarea",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="ParkEvent",
            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()),
                ("name", models.CharField(max_length=255)),
                ("slug", models.SlugField(db_index=False, max_length=255)),
                ("description", models.TextField(blank=True)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("OPERATING", "Operating"),
                            ("CLOSED_TEMP", "Temporarily Closed"),
                            ("CLOSED_PERM", "Permanently Closed"),
                            ("UNDER_CONSTRUCTION", "Under Construction"),
                            ("DEMOLISHED", "Demolished"),
                            ("RELOCATED", "Relocated"),
                        ],
                        default="OPERATING",
                        max_length=20,
                    ),
                ),
                ("opening_date", models.DateField(blank=True, null=True)),
                ("closing_date", models.DateField(blank=True, null=True)),
                (
                    "operating_season",
                    models.CharField(blank=True, max_length=255),
                ),
                (
                    "size_acres",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True),
                ),
                ("website", models.URLField(blank=True)),
                (
                    "average_rating",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=3, null=True),
                ),
                ("ride_count", models.IntegerField(blank=True, null=True)),
                ("coaster_count", models.IntegerField(blank=True, null=True)),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, null=True),
                ),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "operator",
                    models.ForeignKey(
                        db_constraint=False,
                        help_text="Company that operates this park",
                        limit_choices_to={"roles__contains": ["OPERATOR"]},
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to="parks.company",
                    ),
                ),
                (
                    "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.park",
                    ),
                ),
                (
                    "property_owner",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        help_text="Company that owns the property (if different from operator)",
                        limit_choices_to={"roles__contains": ["PROPERTY_OWNER"]},
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to="parks.company",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="ParkLocation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "point",
                    django.contrib.gis.db.models.fields.PointField(
                        blank=True,
                        help_text="Geographic coordinates (longitude, latitude)",
                        null=True,
                        srid=4326,
                    ),
                ),
                (
                    "street_address",
                    models.CharField(blank=True, max_length=255),
                ),
                ("city", models.CharField(db_index=True, max_length=100)),
                ("state", models.CharField(db_index=True, max_length=100)),
                ("country", models.CharField(default="USA", max_length=100)),
                ("postal_code", models.CharField(blank=True, max_length=20)),
                ("highway_exit", models.CharField(blank=True, max_length=100)),
                ("parking_notes", models.TextField(blank=True)),
                ("best_arrival_time", models.TimeField(blank=True, null=True)),
                ("seasonal_notes", models.TextField(blank=True)),
                ("osm_id", models.BigIntegerField(blank=True, null=True)),
                (
                    "osm_type",
                    models.CharField(
                        blank=True,
                        help_text="Type of OpenStreetMap object (node, way, or relation)",
                        max_length=10,
                    ),
                ),
                (
                    "park",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="location",
                        to="parks.park",
                    ),
                ),
            ],
            options={
                "verbose_name": "Park Location",
                "verbose_name_plural": "Park Locations",
                "ordering": ["park__name"],
            },
        ),
        migrations.CreateModel(
            name="ParkReview",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "rating",
                    models.PositiveSmallIntegerField(
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(10),
                        ]
                    ),
                ),
                ("title", models.CharField(max_length=200)),
                ("content", models.TextField()),
                ("visit_date", models.DateField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("is_published", models.BooleanField(default=True)),
                ("moderation_notes", models.TextField(blank=True)),
                ("moderated_at", models.DateTimeField(blank=True, null=True)),
                (
                    "moderated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="moderated_park_reviews",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "park",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reviews",
                        to="parks.park",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="park_reviews",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="ParkReviewEvent",
            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()),
                (
                    "rating",
                    models.PositiveSmallIntegerField(
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(10),
                        ]
                    ),
                ),
                ("title", models.CharField(max_length=200)),
                ("content", models.TextField()),
                ("visit_date", models.DateField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("is_published", models.BooleanField(default=True)),
                ("moderation_notes", models.TextField(blank=True)),
                ("moderated_at", models.DateTimeField(blank=True, null=True)),
                (
                    "moderated_by",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "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.parkreview",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        related_query_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="CompanyHeadquarters",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "street_address",
                    models.CharField(
                        blank=True,
                        help_text="Mailing address if publicly available",
                        max_length=255,
                    ),
                ),
                (
                    "city",
                    models.CharField(
                        db_index=True,
                        help_text="Headquarters city",
                        max_length=100,
                    ),
                ),
                (
                    "state_province",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="State/Province/Region",
                        max_length=100,
                    ),
                ),
                (
                    "country",
                    models.CharField(
                        db_index=True,
                        default="USA",
                        help_text="Country where headquarters is located",
                        max_length=100,
                    ),
                ),
                (
                    "postal_code",
                    models.CharField(
                        blank=True,
                        help_text="ZIP or postal code",
                        max_length=20,
                    ),
                ),
                (
                    "mailing_address",
                    models.TextField(
                        blank=True,
                        help_text="Complete mailing address if different from basic address",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "company",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="headquarters",
                        to="parks.company",
                    ),
                ),
            ],
            options={
                "verbose_name": "Company Headquarters",
                "verbose_name_plural": "Company Headquarters",
                "ordering": ["company__name"],
                "indexes": [
                    models.Index(
                        fields=["city", "country"],
                        name="parks_compa_city_cf9a4e_idx",
                    )
                ],
            },
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="park",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "parks_parkevent" ("average_rating", "closing_date", "coaster_count", "created_at", "description", "id", "name", "opening_date", "operating_season", "operator_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "property_owner_id", "ride_count", "size_acres", "slug", "status", "updated_at", "website") VALUES (NEW."average_rating", NEW."closing_date", NEW."coaster_count", NEW."created_at", NEW."description", NEW."id", NEW."name", NEW."opening_date", NEW."operating_season", NEW."operator_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."property_owner_id", NEW."ride_count", NEW."size_acres", NEW."slug", NEW."status", NEW."updated_at", NEW."website"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_66883",
                    table="parks_park",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="park",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "parks_parkevent" ("average_rating", "closing_date", "coaster_count", "created_at", "description", "id", "name", "opening_date", "operating_season", "operator_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "property_owner_id", "ride_count", "size_acres", "slug", "status", "updated_at", "website") VALUES (NEW."average_rating", NEW."closing_date", NEW."coaster_count", NEW."created_at", NEW."description", NEW."id", NEW."name", NEW."opening_date", NEW."operating_season", NEW."operator_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."property_owner_id", NEW."ride_count", NEW."size_acres", NEW."slug", NEW."status", NEW."updated_at", NEW."website"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_19f56",
                    table="parks_park",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkarea",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "parks_parkareaevent" ("closing_date", "created_at", "description", "id", "name", "opening_date", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "slug", "updated_at") VALUES (NEW."closing_date", NEW."created_at", NEW."description", NEW."id", NEW."name", NEW."opening_date", NEW."park_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."slug", NEW."updated_at"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_13457",
                    table="parks_parkarea",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkarea",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "parks_parkareaevent" ("closing_date", "created_at", "description", "id", "name", "opening_date", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "slug", "updated_at") VALUES (NEW."closing_date", NEW."created_at", NEW."description", NEW."id", NEW."name", NEW."opening_date", NEW."park_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."slug", NEW."updated_at"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_6e5aa",
                    table="parks_parkarea",
                    when="AFTER",
                ),
            ),
        ),
        migrations.AddIndex(
            model_name="parklocation",
            index=models.Index(fields=["city", "state"], name="parks_parkl_city_7cc873_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="parkreview",
            unique_together={("park", "user")},
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkreview",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "parks_parkreviewevent" ("content", "created_at", "id", "is_published", "moderated_at", "moderated_by_id", "moderation_notes", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "rating", "title", "updated_at", "user_id", "visit_date") VALUES (NEW."content", NEW."created_at", NEW."id", NEW."is_published", NEW."moderated_at", NEW."moderated_by_id", NEW."moderation_notes", NEW."park_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."rating", NEW."title", NEW."updated_at", NEW."user_id", NEW."visit_date"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_a99bc",
                    table="parks_parkreview",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="parkreview",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "parks_parkreviewevent" ("content", "created_at", "id", "is_published", "moderated_at", "moderated_by_id", "moderation_notes", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "rating", "title", "updated_at", "user_id", "visit_date") VALUES (NEW."content", NEW."created_at", NEW."id", NEW."is_published", NEW."moderated_at", NEW."moderated_by_id", NEW."moderation_notes", NEW."park_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."rating", NEW."title", NEW."updated_at", NEW."user_id", NEW."visit_date"); RETURN NULL;',
                    hash="[AWS-SECRET-REMOVED]",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_0e40d",
                    table="parks_parkreview",
                    when="AFTER",
                ),
            ),
        ),
    ]
