# Generated by Django 4.2.6 on 2024-01-25 13:10

import django.db.models.deletion
import django_fsm
import wbcore.contrib.icons.models
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("directory", "0006_employeremployeerelationship_position_name"),
        ("geography", "0001_initial"),
        ("agenda", "0008_alter_calendaritem_item_type"),
    ]

    operations = [
        migrations.CreateModel(
            name="League",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("computed_str", models.CharField(blank=True, max_length=512, null=True, verbose_name="Name")),
                ("name", models.CharField(max_length=100, verbose_name="Name")),
                ("established_date", models.DateField(blank=True, null=True, verbose_name="Established Date")),
                ("website", models.URLField(blank=True, null=True, verbose_name="Website")),
                ("points_per_win", models.PositiveIntegerField(verbose_name="Points Per Win")),
                ("points_per_draw", models.PositiveIntegerField(default=1, verbose_name="Points Per Draw")),
                ("points_per_loss", models.PositiveIntegerField(default=0, verbose_name="Points Per Loss")),
            ],
            options={
                "verbose_name": "League",
                "verbose_name_plural": "Leagues",
            },
        ),
        migrations.CreateModel(
            name="Match",
            fields=[
                (
                    "calendaritem_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="agenda.calendaritem",
                    ),
                ),
                ("computed_str", models.CharField(blank=True, max_length=512, null=True, verbose_name="Name")),
                ("date_time", models.DateTimeField(verbose_name="Date Time")),
                (
                    "status",
                    django_fsm.FSMField(
                        choices=[("SCHEDULED", "Scheduled"), ("ONGOING", "Ongoing"), ("FINISHED", "Finished")],
                        default="SCHEDULED",
                        max_length=50,
                        verbose_name="Status",
                    ),
                ),
                ("score_home", models.PositiveIntegerField(default=0, editable=False, verbose_name="Home Score")),
                ("score_away", models.PositiveIntegerField(default=0, editable=False, verbose_name="Away Score")),
                ("task_id", models.CharField(blank=True, editable=False, max_length=50)),
            ],
            options={
                "verbose_name": "Match",
                "verbose_name_plural": "Matches",
                "permissions": [("change_match_status", "Change Match Status")],
            },
            bases=("agenda.calendaritem", models.Model),
        ),
        migrations.CreateModel(
            name="Role",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("title", models.CharField(max_length=100, unique=True, verbose_name="Title")),
                ("slugify_title", models.CharField(blank=True, max_length=100, null=True, unique=True)),
            ],
            options={
                "verbose_name": "Role",
                "verbose_name_plural": "Roles",
            },
        ),
        migrations.CreateModel(
            name="Sport",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("name", models.CharField(max_length=100, unique=True, verbose_name="Name")),
                ("slugify_name", models.CharField(blank=True, max_length=100, null=True, unique=True)),
                ("rules", models.TextField(blank=True, max_length=100, null=True, verbose_name="Rules")),
                ("match_duration", models.PositiveIntegerField(verbose_name="Match Duration (min)")),
            ],
            options={
                "verbose_name": "Sport",
                "verbose_name_plural": "Sports",
            },
        ),
        migrations.CreateModel(
            name="SportPerson",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("computed_str", models.CharField(blank=True, max_length=512, null=True, verbose_name="Name")),
                ("first_name", models.CharField(max_length=255, verbose_name="First Name")),
                ("last_name", models.CharField(max_length=255, verbose_name="Last Name")),
                (
                    "roles",
                    models.ManyToManyField(
                        blank=True, related_name="sport_persons", to="example_app.role", verbose_name="Roles"
                    ),
                ),
            ],
            options={
                "verbose_name": "Person",
                "verbose_name_plural": "Persons",
            },
        ),
        migrations.CreateModel(
            name="Stadium",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("name", models.CharField(max_length=100, unique=True, verbose_name="Name")),
                ("slugify_name", models.CharField(blank=True, max_length=100, null=True, unique=True)),
                ("capacity", models.PositiveIntegerField(blank=True, null=True, verbose_name="Capacity")),
                (
                    "city",
                    models.ForeignKey(
                        blank=True,
                        limit_choices_to={"level": 3},
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="stadiums",
                        to="geography.geography",
                        verbose_name="City",
                    ),
                ),
            ],
            options={
                "verbose_name": "Stadium",
                "verbose_name_plural": "Stadiums",
            },
        ),
        migrations.CreateModel(
            name="Team",
            fields=[
                (
                    "company_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="directory.company",
                    ),
                ),
                ("slugify_name", models.CharField(blank=True, max_length=100, null=True, unique=True)),
                ("founded_date", models.DateField(blank=True, null=True, verbose_name="Founded Date")),
                ("website", models.URLField(default="https://duckduckgo.com/", verbose_name="Website")),
                (
                    "city",
                    models.ForeignKey(
                        blank=True,
                        limit_choices_to={"level": 3},
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="teams",
                        to="geography.geography",
                        verbose_name="City",
                    ),
                ),
                (
                    "coach",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="coached_team",
                        to="example_app.sportperson",
                        verbose_name="Coach",
                    ),
                ),
                (
                    "home_stadium",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="teams_playing",
                        to="example_app.stadium",
                        verbose_name="Home Stadium",
                    ),
                ),
                (
                    "opponents",
                    models.ManyToManyField(
                        blank=True, through="example_app.Match", to="example_app.team", verbose_name="Opponents"
                    ),
                ),
            ],
            options={
                "verbose_name": "Team",
                "verbose_name_plural": "Teams",
            },
            bases=("directory.company",),
        ),
        migrations.CreateModel(
            name="Player",
            fields=[
                (
                    "sportperson_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="example_app.sportperson",
                    ),
                ),
                ("position", models.CharField(blank=True, max_length=50, null=True, verbose_name="Position")),
                (
                    "transfer_value",
                    models.DecimalField(
                        blank=True, decimal_places=2, max_digits=10, null=True, verbose_name="Market Value"
                    ),
                ),
            ],
            options={
                "verbose_name": "Player",
                "verbose_name_plural": "Players",
            },
            bases=("example_app.sportperson",),
        ),
        migrations.CreateModel(
            name="TeamResults",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("points", models.PositiveIntegerField(default=0, verbose_name="Points")),
                ("match_points_for", models.PositiveIntegerField(default=0, verbose_name="Match Points For")),
                ("match_points_against", models.PositiveIntegerField(default=0, verbose_name="Match Points Against")),
                ("match_point_difference", models.IntegerField(default=0, verbose_name="Match Point Difference")),
                ("wins", models.PositiveIntegerField(default=0, verbose_name="Wins")),
                ("draws", models.PositiveIntegerField(default=0, verbose_name="Draws")),
                ("losses", models.PositiveIntegerField(default=0, verbose_name="Losses")),
                ("form", models.CharField(default="-----", max_length=5, verbose_name="Form")),
                (
                    "league",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="results",
                        to="example_app.league",
                        verbose_name="League",
                    ),
                ),
                (
                    "team",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="results",
                        to="example_app.team",
                        verbose_name="Team",
                    ),
                ),
            ],
            options={
                "verbose_name": "Team Result",
                "verbose_name_plural": "Team Results",
            },
        ),
        migrations.AddField(
            model_name="match",
            name="away",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="away_matches",
                to="example_app.team",
                verbose_name="Away",
            ),
        ),
        migrations.AddField(
            model_name="match",
            name="home",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="home_matches",
                to="example_app.team",
                verbose_name="Home",
            ),
        ),
        migrations.AddField(
            model_name="match",
            name="league",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="matches",
                to="example_app.league",
                verbose_name="League",
            ),
        ),
        migrations.AddField(
            model_name="match",
            name="referee",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="refereed_matches",
                to="example_app.sportperson",
            ),
        ),
        migrations.AddField(
            model_name="match",
            name="sport",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="matches",
                to="example_app.sport",
                verbose_name="Sport",
            ),
        ),
        migrations.AddField(
            model_name="match",
            name="stadium",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="matches",
                to="example_app.stadium",
                verbose_name="Stadium",
            ),
        ),
        migrations.AddField(
            model_name="league",
            name="commissioner",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="commissioned_leagues",
                to="example_app.sportperson",
                verbose_name="Commissioner",
            ),
        ),
        migrations.AddField(
            model_name="league",
            name="country",
            field=models.ForeignKey(
                blank=True,
                limit_choices_to={"level": 1},
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="leagues",
                to="geography.geography",
                verbose_name="Country",
            ),
        ),
        migrations.AddField(
            model_name="league",
            name="sport",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="leagues",
                to="example_app.sport",
                verbose_name="Sport",
            ),
        ),
        migrations.AddField(
            model_name="league",
            name="teams",
            field=models.ManyToManyField(
                blank=True,
                related_name="leagues",
                through="example_app.TeamResults",
                to="example_app.team",
                verbose_name="Teams",
            ),
        ),
        migrations.CreateModel(
            name="EventType",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("name", models.CharField(max_length=100, verbose_name="Name")),
                (
                    "points",
                    models.PositiveIntegerField(
                        default=1,
                        help_text="Number of points awarded to a player's team per event",
                        verbose_name="Points",
                    ),
                ),
                (
                    "icon",
                    wbcore.contrib.icons.models.IconField(
                        default="sports_soccer", max_length=128, verbose_name="Icon"
                    ),
                ),
                (
                    "sport",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="event_types",
                        to="example_app.sport",
                        verbose_name="Sport",
                    ),
                ),
            ],
            options={
                "verbose_name": "Event Type",
                "verbose_name_plural": "Event Types",
            },
        ),
        migrations.CreateModel(
            name="Event",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("minute", models.PositiveIntegerField(verbose_name="Minute")),
                (
                    "event_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="events",
                        to="example_app.eventtype",
                        verbose_name="Event Type",
                    ),
                ),
                (
                    "match",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="events",
                        to="example_app.match",
                        verbose_name="Match",
                    ),
                ),
                (
                    "person",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="events",
                        to="example_app.sportperson",
                        verbose_name="Person",
                    ),
                ),
            ],
            options={
                "verbose_name": "Event",
                "verbose_name_plural": "Events",
            },
        ),
        migrations.AddConstraint(
            model_name="teamresults",
            constraint=models.UniqueConstraint(fields=("team", "league"), name="unique_team_league"),
        ),
        migrations.AddField(
            model_name="player",
            name="current_team",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="current_players",
                to="example_app.team",
                verbose_name="Current Team",
            ),
        ),
        migrations.AddField(
            model_name="player",
            name="former_teams",
            field=models.ManyToManyField(
                blank=True, related_name="former_players", to="example_app.team", verbose_name="Former Teams"
            ),
        ),
        migrations.AddConstraint(
            model_name="match",
            constraint=models.UniqueConstraint(fields=("home", "away", "date_time"), name="match_home_away_date_time"),
        ),
        migrations.AddConstraint(
            model_name="match",
            constraint=models.CheckConstraint(
                check=models.Q(("home", models.F("away")), _negated=True), name="check_match_home_away"
            ),
        ),
        migrations.AddConstraint(
            model_name="league",
            constraint=models.UniqueConstraint(fields=("name", "sport"), name="league_name_sport"),
        ),
        migrations.AddConstraint(
            model_name="eventtype",
            constraint=models.UniqueConstraint(fields=("name", "sport"), name="event_type_name_sport"),
        ),
        migrations.AddConstraint(
            model_name="event",
            constraint=models.UniqueConstraint(
                fields=("person", "match", "minute", "event_type"), name="event_person_match_minute_event_type"
            ),
        ),
    ]
