# Generated by Django 6.1.1 on 2026-10-06 18:09

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


class Migration(migrations.Migration):

    dependencies = [
        ('clubs', '0003_club_squad_membership'),
        ('matches', '0003_matchsimulationsnapshot_matchsimulationrun_and_more'),
        ('players', '0002_player_integrity_constraints'),
    ]

    operations = [
        migrations.CreateModel(
            name='MatchSimulationReport',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('schema_version', models.PositiveSmallIntegerField(default=1)),
                ('builder_key', models.CharField(max_length=64)),
                ('builder_version', models.CharField(max_length=64)),
                ('report_payload', models.JSONField()),
                ('report_hash', models.CharField(max_length=64)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('run', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='report', to='matches.matchsimulationrun')),
            ],
            options={
                'ordering': ['created_at', 'id'],
            },
        ),
        migrations.CreateModel(
            name='MatchEvent',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('sequence', models.PositiveSmallIntegerField()),
                ('minute', models.PositiveSmallIntegerField()),
                ('event_type', models.CharField(choices=[('GOAL', 'Goal')], max_length=16)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('club', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='match_events', to='clubs.club')),
                ('match', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='events', to='matches.match')),
                ('player', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='match_events', to='players.player')),
                ('report', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='events', to='matches.matchsimulationreport')),
            ],
            options={
                'ordering': ['match_id', 'minute', 'sequence'],
            },
        ),
        migrations.AddConstraint(
            model_name='matchsimulationreport',
            constraint=models.CheckConstraint(condition=models.Q(('schema_version__gte', 1)), name='sim_report_schema_gte_1'),
        ),
        migrations.AddConstraint(
            model_name='matchsimulationreport',
            constraint=models.CheckConstraint(condition=models.Q(('builder_key', ''), _negated=True), name='sim_report_builder_key_not_empty'),
        ),
        migrations.AddConstraint(
            model_name='matchsimulationreport',
            constraint=models.CheckConstraint(condition=models.Q(('builder_version', ''), _negated=True), name='sim_report_builder_version_not_empty'),
        ),
        migrations.AddIndex(
            model_name='matchevent',
            index=models.Index(fields=['match', 'minute', 'sequence'], name='event_match_time_idx'),
        ),
        migrations.AddIndex(
            model_name='matchevent',
            index=models.Index(fields=['player', 'match'], name='event_player_match_idx'),
        ),
        migrations.AddIndex(
            model_name='matchevent',
            index=models.Index(fields=['club', 'match'], name='event_club_match_idx'),
        ),
        migrations.AddConstraint(
            model_name='matchevent',
            constraint=models.UniqueConstraint(fields=('match', 'sequence'), name='uq_match_event_sequence'),
        ),
        migrations.AddConstraint(
            model_name='matchevent',
            constraint=models.CheckConstraint(condition=models.Q(('minute__gte', 1), ('minute__lte', 90)), name='event_minute_1_90'),
        ),
        migrations.AddConstraint(
            model_name='matchevent',
            constraint=models.CheckConstraint(condition=models.Q(('sequence__gte', 1)), name='event_sequence_gte_1'),
        ),
        migrations.AddConstraint(
            model_name='matchevent',
            constraint=models.CheckConstraint(condition=models.Q(('event_type__in', ['GOAL'])), name='event_valid_type'),
        ),
    ]
