# Generated by Django 2.2.4 on 2019-10-17 11:51

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

import pretix.base.models.base
import pretix.base.models.fields
import pretix.base.models.giftcards


def fwd(app, schema_editor):
    Team = app.get_model('pretixbase', 'Team')
    Team.objects.filter(can_change_organizer_settings=True).update(can_manage_gift_cards=True)


class Migration(migrations.Migration):
    dependencies = [
        ('pretixbase', '0137_auto_20191015_1141'),
    ]

    operations = [
        migrations.CreateModel(
            name='GiftCard',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False)),
                ('issuance', models.DateTimeField(auto_now_add=True)),
                ('secret', models.CharField(db_index=True, default=pretix.base.models.giftcards.gen_giftcard_secret,
                                            max_length=190)),
                ('currency', models.CharField(max_length=10)),
                ('issued_in', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT,
                                                related_name='issued_gift_cards', to='pretixbase.OrderPosition')),
                ('issuer',
                 models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='issued_gift_cards',
                                   to='pretixbase.Organizer')),
                ('testmode', django.db.models.BooleanField(default=False)),
            ],
            options={
                'unique_together': {('secret', 'issuer')},
            },
            bases=(models.Model, pretix.base.models.base.LoggingMixin),
        ),
        migrations.AddField(
            model_name='item',
            name='issue_giftcard',
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name='team',
            name='can_manage_gift_cards',
            field=models.BooleanField(default=False),
        ),
        migrations.AlterField(
            model_name='question',
            name='dependency_values',
            field=pretix.base.models.fields.MultiStringField(default=[]),
        ),
        migrations.AlterField(
            model_name='voucher',
            name='item',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vouchers',
                                    to='pretixbase.Item'),
        ),
        migrations.AlterField(
            model_name='voucher',
            name='quota',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vouchers',
                                    to='pretixbase.Quota'),
        ),
        migrations.AlterField(
            model_name='voucher',
            name='variation',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vouchers',
                                    to='pretixbase.ItemVariation'),
        ),
        migrations.CreateModel(
            name='GiftCardTransaction',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False)),
                ('datetime', models.DateTimeField(auto_now_add=True)),
                ('value', models.DecimalField(decimal_places=2, max_digits=10)),
                ('card', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions',
                                           to='pretixbase.GiftCard')),
                ('order', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT,
                                            related_name='gift_card_transactions', to='pretixbase.Order')),
                ('payment', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT,
                                              related_name='gift_card_transactions', to='pretixbase.OrderPayment')),
                ('refund', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT,
                                             related_name='gift_card_transactions', to='pretixbase.OrderRefund')),
            ],
            options={
                'ordering': ('datetime',),
            },
        ),
        migrations.CreateModel(
            name='GiftCardAcceptance',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False)),
                ('collector', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                                related_name='gift_card_issuer_acceptance', to='pretixbase.Organizer')),
                ('issuer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                             related_name='gift_card_collector_acceptance', to='pretixbase.Organizer')),
            ],
        ),
        migrations.RunPython(
            fwd, migrations.RunPython.noop
        ),
    ]
