# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-06 21:53
from __future__ import unicode_literals

import django.db.migrations.operations.special
import django.db.models.deletion
from django.db import migrations, models


def runfwd(app, schema_editor):
    EventSettingsStore = app.get_model('pretixbase', 'Event_SettingsStore')
    AppConfiguration = app.get_model('pretixdroid', 'AppConfiguration')

    for setting in EventSettingsStore.objects.filter(key='pretixdroid_key'):
        AppConfiguration.objects.create(
            event=setting.object,
            key=setting.value,
            all_items=True
        )
        setting.delete()


class Migration(migrations.Migration):

    replaces = [('pretixdroid', '0003_appconfiguration'), ('pretixdroid', '0004_auto_20171124_1657'), ('pretixdroid', '0005_auto_20180106_2122')]

    dependencies = [
        ('pretixbase', '0074_auto_20170825_1258'),
        ('pretixdroid', '0002_auto_20161208_1644'),
        ('pretixbase', '0077_auto_20171124_1629'),
    ]

    operations = [
        migrations.CreateModel(
            name='AppConfiguration',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.CharField(db_index=True, max_length=190)),
                ('all_items', models.BooleanField(default=True)),
                ('allow_search', models.BooleanField(default=True)),
                ('show_info', models.BooleanField(default=True)),
                ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pretixbase.Event')),
                ('items', models.ManyToManyField(blank=True, to='pretixbase.Item')),
            ],
        ),
        migrations.RunPython(
            code=runfwd,
            reverse_code=django.db.migrations.operations.special.RunPython.noop,
        ),
        migrations.AddField(
            model_name='appconfiguration',
            name='list',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pretixbase.CheckinList'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='all_items',
            field=models.BooleanField(default=True, verbose_name='Can scan all products'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='allow_search',
            field=models.BooleanField(default=True, help_text='If disabled, the device can not search for attendees by name. pretixdroid 1.6 or newer only.', verbose_name='Search allowed'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='items',
            field=models.ManyToManyField(blank=True, to='pretixbase.Item', verbose_name='Can scan these products'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='show_info',
            field=models.BooleanField(default=True, help_text='If disabled, the device can not see how many tickets exist and how many are already scanned. pretixdroid 1.6 or newer only.', verbose_name='Show information'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='list',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pretixbase.CheckinList'),
        ),
        migrations.AddField(
            model_name='appconfiguration',
            name='app',
            field=models.CharField(choices=[('pretixdroid', 'pretixdroid – for Android smartphones'), ('pretixdesk', 'pretixdesk – for desktop computers')], default='pretixdroid', max_length=190, verbose_name='Scan software'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='allow_search',
            field=models.BooleanField(default=True, help_text='If disabled, the device can not search for attendees by name. pretixdroid 1.6 or pretixdesk only.', verbose_name='Search allowed'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='list',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pretixbase.CheckinList', verbose_name='Check-in list'),
        ),
        migrations.AlterField(
            model_name='appconfiguration',
            name='show_info',
            field=models.BooleanField(default=True, help_text='If disabled, the device can not see how many tickets exist and how many are already scanned. pretixdroid 1.6 or pretixdesk only.', verbose_name='Show information'),
        ),
    ]
