# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-07-11 15:10
from __future__ import unicode_literals

from django.db import migrations


def convert_space_category_to_location_group(apps, schema_editor):
    Space = apps.get_model('mapdata', 'Space')
    LocationGroupCategory = apps.get_model('mapdata', 'LocationGroupCategory')
    category = LocationGroupCategory.objects.create(name='spacecategory', titles={
        'en': 'Space Category',
        'de': 'Raumkategorie',
    }, single=True, allow_levels=False, allow_spaces=True, allow_areas=False, allow_pois=False, priority=-1)
    space_categories = (
        ('stairs', {'en': 'Stairs', 'de': 'Treppe'}, '#dddddd'),
        ('escalator', {'en': 'Escalator', 'de': 'Rolltreppe'}, '#bbbbbb'),
        ('elevator', {'en': 'Elevator', 'de': 'Aufzug'}, '#00ffff')
    )
    for i, (name, titles, color) in enumerate(space_categories):
        group = category.groups.create(titles=titles, can_search=False, can_describe=False, color=color, priority=i+1)
        group.spaces.set(Space.objects.filter(category=name))


class Migration(migrations.Migration):

    dependencies = [
        ('mapdata', '0021_auto_20170710_1916'),
    ]

    operations = [
        migrations.RunPython(convert_space_category_to_location_group),
        migrations.RemoveField(
            model_name='space',
            name='category',
        ),
    ]
