from django.db import migrations

SEED_COUNTRIES = (
    ('PK', 'Pakistan'),
    ('IN', 'India'),
    ('IR', 'Iran'),
    ('AF', 'Afghanistan'),
    ('CN', 'China'),
)


def seed_countries(apps, schema_editor):
    Country = apps.get_model('core', 'Country')
    for code, name in SEED_COUNTRIES:
        Country.objects.update_or_create(code=code, defaults={'name': name})


def unseed_countries(apps, schema_editor):
    Country = apps.get_model('core', 'Country')
    Country.objects.filter(code__in=[code for code, _ in SEED_COUNTRIES]).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0029_country_freight_route'),
    ]

    operations = [
        migrations.RunPython(seed_countries, unseed_countries),
    ]
