from django.db import migrations, models


def forwards_registration_to_noc(apps, schema_editor):
    VehicleDocument = apps.get_model('accounts', 'VehicleDocument')
    VehicleDocument.objects.filter(document_type='REGISTRATION').update(document_type='NOC')


def backwards_noc_to_registration(apps, schema_editor):
    VehicleDocument = apps.get_model('accounts', 'VehicleDocument')
    VehicleDocument.objects.filter(document_type='NOC').update(document_type='REGISTRATION')


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0025_shipper_national_id_passport_fields'),
    ]

    operations = [
        migrations.RunPython(forwards_registration_to_noc, backwards_noc_to_registration),
        migrations.AlterField(
            model_name='vehicledocument',
            name='document_type',
            field=models.CharField(
                choices=[
                    ('NOC', 'NOC'),
                    ('INSURANCE', 'Insurance'),
                    ('PERMIT', 'Permit'),
                    ('FITNESS', 'Fitness certificate'),
                    ('OTHER', 'Other'),
                ],
                max_length=20,
            ),
        ),
    ]
