import django.db.models.deletion
import uuid
from django.db import migrations, models
from django.db.models.functions import Lower


class Migration(migrations.Migration):
    dependencies = [("matches", "0020_referee_var_match_mechanics")]

    operations = [
        migrations.CreateModel(
            name="CountryMatchEnvironmentProfile",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("country", models.CharField(max_length=80)),
                ("climate_zone", models.CharField(choices=[("TEMPERATE", "Temperate"), ("CONTINENTAL", "Continental"), ("MEDITERRANEAN", "Mediterranean"), ("ARID", "Arid"), ("TROPICAL", "Tropical"), ("COLD", "Cold")], default="TEMPERATE", max_length=20)),
                ("mean_temperature_c", models.SmallIntegerField(default=14)),
                ("seasonal_amplitude_c", models.PositiveSmallIntegerField(default=11)),
                ("season_peak_month", models.PositiveSmallIntegerField(default=7)),
                ("humidity_index", models.PositiveSmallIntegerField(default=55)),
                ("rainfall_index", models.PositiveSmallIntegerField(default=45)),
                ("wind_index", models.PositiveSmallIntegerField(default=35)),
                ("snow_index", models.PositiveSmallIntegerField(default=10)),
                ("is_active", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={"ordering": ["country"]},
        ),
        migrations.CreateModel(
            name="MatchEnvironmentEvidence",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("venue_source", models.CharField(default="FALLBACK", max_length=32)),
                ("venue_reference", models.CharField(blank=True, default="", max_length=80)),
                ("climate_source", models.CharField(default="DEFAULT", max_length=32)),
                ("environment_payload", models.JSONField(default=dict)),
                ("effects_payload", models.JSONField(default=dict)),
                ("evidence_hash", models.CharField(max_length=64)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("match", models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name="environment_evidence", to="matches.match")),
                ("snapshot", models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name="environment_evidence", to="matches.matchsimulationsnapshot")),
            ],
            options={"ordering": ["match_id"]},
        ),
        migrations.AlterField(
            model_name="interactivematchsession",
            name="engine_version",
            field=models.CharField(default="3.4.0", max_length=64),
        ),
        migrations.AddConstraint(
            model_name="countrymatchenvironmentprofile",
            constraint=models.UniqueConstraint(Lower("country"), name="uq_country_match_env_country_ci"),
        ),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(mean_temperature_c__gte=-15, mean_temperature_c__lte=40), name="country_env_mean_temp")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(seasonal_amplitude_c__lte=30), name="country_env_season_amp")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(season_peak_month__gte=1, season_peak_month__lte=12), name="country_env_peak_month")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(humidity_index__lte=100), name="country_env_humidity")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(rainfall_index__lte=100), name="country_env_rainfall")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(wind_index__lte=100), name="country_env_wind")),
        migrations.AddConstraint(model_name="countrymatchenvironmentprofile", constraint=models.CheckConstraint(condition=models.Q(snow_index__lte=100), name="country_env_snow")),
        migrations.AddConstraint(model_name="matchenvironmentevidence", constraint=models.CheckConstraint(condition=~models.Q(evidence_hash=""), name="match_env_evidence_hash_nonempty")),
    ]
