# Generated by Django 2.2.12 on 2020-04-04 21:44

from django.db import migrations

product_classes = [
    'Haushalt, Garten, Tier & Baumarkt', 'Blumen', 'Beauty & Drogerie & '
    'Lebensmittel', 'Kleidung, Schuhe, Schmuck', 'Bücher & Musik', 'Büro '
    '& IT', 'Spielzeug & Baby', 'Kunst', 'Sport & Freizeit'
]


def forwards_func(apps, schema_editor):
    # We get the model from the versioned app registry;
    # if we directly import it, it'll be the wrong version
    ProductClass = apps.get_model("catalogue", "ProductClass")
    AttributeOptionGroup = apps.get_model("catalogue", "AttributeOptionGroup")
    db_alias = schema_editor.connection.alias
    ProductClass.objects.using(db_alias).bulk_create([
        ProductClass(name=name) for name in product_classes
    ])
    size_grp = AttributeOptionGroup.objects.using(db_alias).create(name='Größen')
    ProductClass.objects.using(db_alias)\
        .get(name="Kleidung, Schuhe, Schmuck").attributes.create(
        name='Größe', code='size', type="option", option_group=size_grp
    )


def reverse_func(apps, schema_editor):
    ProductClass = apps.get_model("catalogue", "ProductClass")
    db_alias = schema_editor.connection.alias
    ProductClass.objects.using(db_alias).filter(name__in=product_classes)\
        .delete()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]
