# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-05 19:13
from __future__ import unicode_literals

from django.db import migrations


INITIAL_CATEGORIES = [
    'bug',
    'enhancement',
    'documentation',
    'proposal',
    'task',
]


class Migration(migrations.Migration):
    """A data migration to create initial IssueCategory model instances
    """

    def create_initial_issue_categories(apps, schema_editor):
        IssueCategory = apps.get_model('medeina', 'IssueCategory')

        for category in INITIAL_CATEGORIES:
            ic = IssueCategory.objects.create(name=category)

            print("\n Created initial Issue category: '{0}'".format(ic.name))

    def remove_initial_issue_categories(apps, schema_editor):
        IssueCategory = apps.get_model('medeina', 'IssueCategory')

        for category in INITIAL_CATEGORIES:
            category_instance = IssueCategory.objects.filter(
                name=category
            ).first()

            if category_instance:
                category_instance.delete()

                print(
                    "\n Removed initial Issue category: '{0}'".format(
                        category_instance.name
                    )
                )

    dependencies = [
        ('medeina', '0002_auto_20180405_1905'),
    ]

    operations = [
        migrations.RunPython(
            create_initial_issue_categories,
            remove_initial_issue_categories
        ),
    ]
