# Generated by Django 3.2.15 on 2022-10-19 18:34

from django.db import migrations
from dataservices.views import MetadataMixin


def seed_ftas(apps, schema_editor):
    # Seed the database with UK trade agreements records.
    UKFreeTradeAgreement = apps.get_model('dataservices', 'UKFreeTradeAgreement')
    Country = apps.get_model('dataservices', 'Country')

    fta_records = [
        ('AU', 'Australia'),
        ('NZ', 'New Zealand'),
        ('JP', 'Japan Comprehensive Economic Partnership Agreement'),
        ('SG', 'Singapore Digital Economy Agreement'),
    ]

    for country_iso2, fta_name in fta_records:
        try:
            country = Country.objects.get(iso2=country_iso2)
        except Country.DoesNotExist:
            country = None

        UKFreeTradeAgreement.objects.get_or_create(country=country, name=fta_name)


def rollback(apps, schema_editor):
    UKFreeTradeAgreement = apps.get_model('dataservices', 'UKFreeTradeAgreement')

    UKFreeTradeAgreement.objects.all().delete()


class Migration(migrations.Migration):

    dependencies = [
        ('dataservices', '0044_ukfreetradeagreement'),
    ]

    operations = [
        migrations.RunPython(seed_ftas, rollback),
    ]
