# Generated by Django 3.2.14 on 2022-07-06 12:50

import display.fields.my_pickled_object_field
import django.core.validators
from django.db import migrations, models

existing_gates = {}


def store_existing_gates(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Route = apps.get_model("display", "Route")
    for route in Route.objects.using(db_alias).all():
        existing_gates[route.pk] = (route.takeoff_gate, route.landing_gate)


def restore_existing_gates(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Route = apps.get_model("display", "Route")
    for route in Route.objects.using(db_alias).all():
        takeoff, landing = existing_gates[route.pk]
        if takeoff is not None:
            route.takeoff_gates = [takeoff]
        if landing is not None:
            route.landing_gates = [landing]
        route.save()


class Migration(migrations.Migration):
    dependencies = [
        ('display', '0081_scorecard_free_text'),
    ]

    operations = [
        migrations.RunPython(store_existing_gates),
        migrations.RemoveField(
            model_name='route',
            name='landing_gate',
        ),
        migrations.RemoveField(
            model_name='route',
            name='takeoff_gate',
        ),
        migrations.AddField(
            model_name='route',
            name='landing_gates',
            field=display.fields.my_pickled_object_field.MyPickledObjectField(default=list, editable=False),
        ),
        migrations.AddField(
            model_name='route',
            name='takeoff_gates',
            field=display.fields.my_pickled_object_field.MyPickledObjectField(default=list, editable=False),
        ),
        migrations.RunPython(restore_existing_gates),
        migrations.AlterField(
            model_name='flightorderconfiguration',
            name='map_line_width',
            field=models.FloatField(default=1, validators=[django.core.validators.MinValueValidator(0.1),
                                                           django.core.validators.MaxValueValidator(10.0)]),
        ),
        migrations.AlterField(
            model_name='flightorderconfiguration',
            name='map_minute_mark_line_width',
            field=models.FloatField(default=1, validators=[django.core.validators.MinValueValidator(0.1),
                                                           django.core.validators.MaxValueValidator(10.0)]),
        ),
        migrations.AlterField(
            model_name='flightorderconfiguration',
            name='map_orientation',
            field=models.CharField(choices=[('landscape', 'Landscape'), ('portrait', 'Portrait')], default='portrait',
                                   max_length=30),
        ),
        migrations.AlterField(
            model_name='flightorderconfiguration',
            name='map_source',
            field=models.CharField(blank=True,
                                   choices=[('osm', 'OSM'), ('fc', 'Flight Contest'), ('mto', 'MapTiler Outdoor'),
                                            ('cyclosm', 'CycleOSM')], default='cyclosm', max_length=50),
        ),
        migrations.AlterField(
            model_name='gatescore',
            name='gate_type',
            field=models.CharField(choices=[('tp', 'Turning Point'), ('sp', 'Starting Point'), ('fp', 'Finish Point'),
                                            ('secret', 'Secret Point'), ('to', 'Takeoff Gate'), ('ldg', 'Landing Gate'),
                                            ('isp', 'Intermediary Starting Point'),
                                            ('ifp', 'Intermediary Finish Point')], max_length=20),
        ),
        migrations.AlterField(
            model_name='scorecard',
            name='calculator',
            field=models.CharField(
                choices=[('precision', 'Precision'), ('anr_corridor', 'ANR Corridor'), ('poker', 'Pilot Poker Run'),
                         ('landing', 'Landing'), ('airsports', 'Air Sports Race')], default='precision',
                help_text='Supported calculator types', max_length=20),
        ),
        migrations.AlterField(
            model_name='trackannotation',
            name='gate_type',
            field=models.CharField(blank=True,
                                   choices=[('tp', 'Turning Point'), ('sp', 'Starting Point'), ('fp', 'Finish Point'),
                                            ('secret', 'Secret Point'), ('to', 'Takeoff Gate'), ('ldg', 'Landing Gate'),
                                            ('isp', 'Intermediary Starting Point'),
                                            ('ifp', 'Intermediary Finish Point')], default='tp', max_length=30),
        ),
    ]
