# Generated by Django 2.0.1 on 2018-01-18 02:48

from django.db import migrations


def load_basic_data(apps, schema_editor):
    db_alias = schema_editor.connection.alias

    ThingType = apps.get_model('campaign', 'ThingType')
    Attribute = apps.get_model('campaign', 'Attribute')

    ThingType.objects.using(db_alias).bulk_create([
        ThingType(name='Location'),
        ThingType(name='Faction'),
        ThingType(name='NPC')
    ])

    thing_type_faction = ThingType.objects.get(name='Faction')
    thing_type_npc = ThingType.objects.get(name='NPC')

    attribute_faction_leader = Attribute(thing_type=thing_type_faction, name='Leader')
    attribute_faction_attitude = Attribute(thing_type=thing_type_faction, name='Attitude')
    attribute_faction_power = Attribute(thing_type=thing_type_faction, name='Power')
    attribute_faction_reach = Attribute(thing_type=thing_type_faction, name='Reach')

    attribute_npc_race = Attribute(thing_type=thing_type_npc, name='Race')
    attribute_npc_attitude = Attribute(thing_type=thing_type_npc, name='Attitude')
    attribute_npc_occupation = Attribute(thing_type=thing_type_npc, name='Occupation')
    attribute_npc_link = Attribute(thing_type=thing_type_npc, name='Link')

    Attribute.objects.using(db_alias).bulk_create([
        attribute_faction_leader,
        attribute_faction_attitude,
        attribute_faction_power,
        attribute_faction_reach,
        attribute_npc_race,
        attribute_npc_attitude,
        attribute_npc_occupation,
        attribute_npc_link
    ])


def delete_basic_data(apps, schema_editor):
    db_alias = schema_editor.connection.alias

    ThingType = apps.get_model('campaign', 'ThingType')

    ThingType.objects.using(db_alias).filter(name='Location').delete()
    ThingType.objects.using(db_alias).filter(name='Faction').delete()
    ThingType.objects.using(db_alias).filter(name='NPC').delete()


class Migration(migrations.Migration):

    dependencies = [
        ('campaign', '0008_auto_20180117_1822'),
    ]

    operations = [
        migrations.RunPython(load_basic_data, delete_basic_data)
    ]
