# Generated by Django 4.1 on 2022-10-31 22:27

from django.db import migrations, models


def meta_to_roster(apps, schema_editor):
    model = apps.get_model("roster", "RollingStock")

    for row in model.objects.all():
        if row.decoder:
            decoder_interface = row.decoder.interface
            row.__dict__["decoder_interface"] = decoder_interface
            row.save(update_fields=["decoder_interface"])


class Migration(migrations.Migration):

    dependencies = [
        ("roster", "0012_rollingstockjournal"),
    ]

    operations = [
        migrations.AddField(
            model_name="rollingstock",
            name="decoder_interface",
            field=models.PositiveSmallIntegerField(
                blank=True,
                choices=[
                    (1, "NEM651"),
                    (2, "NEM652"),
                    (3, "PluX"),
                    (4, "21MTC"),
                    (5, "Next18/Next18S"),
                ],
                null=True,
            ),
        ),
        migrations.RunPython(
            meta_to_roster,
            reverse_code=migrations.RunPython.noop
        ),
    ]
