# Generated by Django 2.2.13 on 2020-06-17 06:33
import csv
import os

from django.conf import settings
from django.db import migrations

SEED_DATA_PATH = os.path.join(settings.BASE_DIR, "fixtures/gov_agency.csv")


def forward_func(apps, schema_editor):
    Agency = apps.get_model("api", "GovAgency")
    with open(SEED_DATA_PATH, "r") as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        next(reader)
        seed_agencies = []
        for row in reader:
            agency_name = row[0]
            zip_code = row[1]
            address = row[2]
            gov_agency = Agency(
                agency_name=agency_name,
                zip_code=zip_code,
                address=address
            )
            seed_agencies.append(gov_agency)

    Agency.objects.bulk_create(seed_agencies)


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0024_factory_display_number'),
    ]

    operations = [
        migrations.RunPython(
            code=forward_func,
            reverse_code=None,
        ),
    ]
