# Initial migration: a single corptools-only schema (originally a squash of the
# pre-corptools 0001..0025 history, which dropped the historical aa-memberaudit
# references so fresh installs no longer require aa-memberaudit).
#
# The replaced 0001..0025 files were deleted in 0.4.0 and `replaces` dropped, once every
# supported install was on >= 0.3.0 (where this node is already recorded as applied).
# An install still on 0.2.0 must upgrade via 0.3.0 first; it cannot jump straight to 0.4.0.
import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('corptools', '__first__'),
        ('eveonline', '__first__'),
        ('eveuniverse', '__first__'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='General',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
            options={
                'permissions': (('basic_access', 'Can access the shop app'), ('manage_corporation_shops', 'Can manage corporation shops')),
                'managed': False,
                'default_permissions': (),
            },
        ),
        migrations.CreateModel(
            name='Buyer',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('character_id', models.PositiveBigIntegerField(unique=True)),
                ('character_name', models.CharField(max_length=255)),
                ('discord_handle', models.CharField(blank=True, max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name='CharacterBlueprint',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('item_id', models.PositiveBigIntegerField(unique=True)),
                ('type_id', models.PositiveIntegerField()),
                ('me', models.PositiveSmallIntegerField()),
                ('te', models.PositiveSmallIntegerField()),
                ('runs', models.IntegerField()),
                ('quantity', models.IntegerField()),
                ('character', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='corptools.characteraudit')),
            ],
        ),
        migrations.CreateModel(
            name='CorporationBlueprint',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('item_id', models.PositiveBigIntegerField(unique=True)),
                ('type_id', models.PositiveIntegerField()),
                ('me', models.PositiveSmallIntegerField()),
                ('te', models.PositiveSmallIntegerField()),
                ('runs', models.IntegerField()),
                ('quantity', models.IntegerField()),
                ('corporation_audit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='corptools.corporationaudit')),
            ],
        ),
        migrations.CreateModel(
            name='Order',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reference', models.CharField(default='', editable=False, max_length=5, unique=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('accepted', 'Accepted'), ('completed', 'Completed'), ('declined', 'Declined'), ('cancelled', 'Cancelled')], default='pending', max_length=10)),
                ('additional_info', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('buyer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='orders', to='shop.buyer')),
            ],
        ),
        migrations.CreateModel(
            name='OrderLine',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('section', models.CharField(max_length=20)),
                ('quantity', models.PositiveIntegerField()),
                ('unit_price', models.PositiveBigIntegerField(default=0)),
                ('listing_id', models.PositiveIntegerField(blank=True, null=True)),
                ('label', models.CharField(blank=True, max_length=100)),
                ('eve_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='eveuniverse.evetype')),
                ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='shop.order')),
            ],
        ),
        migrations.CreateModel(
            name='Shop',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(help_text='Globally unique. Lowercase letters, numbers and dashes.', unique=True, validators=[django.core.validators.RegexValidator(message='Slug may contain lowercase letters, numbers and single dashes only.', regex='^[a-z0-9]+(-[a-z0-9]+)*$')])),
                ('name', models.CharField(max_length=100)),
                ('shop_type', models.CharField(choices=[('personal', 'Personal'), ('corporation', 'Corporation')], default='personal', max_length=12)),
                ('is_published', models.BooleanField(default=False)),
                ('enabled_sections', models.JSONField(blank=True, default=list)),
                ('description', models.TextField(blank=True, default='')),
                ('discord_webhook', models.URLField(blank=True, max_length=500)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('corporation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='shops', to='eveonline.evecorporationinfo')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shops', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.AddField(
            model_name='order',
            name='shop',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='shop.shop'),
        ),
        migrations.CreateModel(
            name='BpcListing',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('featured', models.BooleanField(default=False)),
                ('featured_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('eve_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='eveuniverse.evetype')),
                ('shop', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bpc_listings', to='shop.shop')),
            ],
        ),
        migrations.CreateModel(
            name='ShopSource',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('section', models.CharField(choices=[('hulls', 'Hulls'), ('modules', 'Modules'), ('bpc', 'BPC'), ('fitted', 'Fitted Ships')], max_length=20)),
                ('location_id', models.BigIntegerField()),
                ('container_item_id', models.PositiveBigIntegerField(blank=True, null=True)),
                ('container_name', models.CharField(blank=True, default='', max_length=100)),
                ('price_mode', models.CharField(choices=[('fixed', 'Fixed'), ('jita_buy_pct', '% Jita Buy'), ('jita_sell_pct', '% Jita Sell')], default='fixed', max_length=20)),
                ('price_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
                ('character_audit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='corptools.characteraudit')),
                ('corporation_audit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='corptools.corporationaudit')),
                ('shop', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sources', to='shop.shop')),
            ],
        ),
        migrations.CreateModel(
            name='BpcVariant',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('me', models.PositiveSmallIntegerField()),
                ('te', models.PositiveSmallIntegerField()),
                ('runs', models.IntegerField()),
                ('stock', models.PositiveIntegerField(default=0)),
                ('price', models.PositiveBigIntegerField(default=0)),
                ('price_per_run', models.PositiveBigIntegerField(default=0)),
                ('hidden', models.BooleanField(default=False)),
                ('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='variants', to='shop.bpclisting')),
            ],
            options={
                'constraints': [models.UniqueConstraint(fields=('listing', 'me', 'te', 'runs'), name='uniq_bpc_variant')],
            },
        ),
        migrations.CreateModel(
            name='ModuleListing',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('featured', models.BooleanField(default=False)),
                ('featured_at', models.DateTimeField(blank=True, null=True)),
                ('price', models.PositiveBigIntegerField(default=0)),
                ('stock', models.PositiveIntegerField(default=0)),
                ('price_mode', models.CharField(choices=[('fixed', 'Fixed'), ('jita_buy_pct', '% Jita Buy'), ('jita_sell_pct', '% Jita Sell')], default='fixed', max_length=20)),
                ('price_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('eve_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='eveuniverse.evetype')),
                ('shop', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='module_listings', to='shop.shop')),
            ],
            options={
                'constraints': [models.UniqueConstraint(fields=('shop', 'eve_type'), name='uniq_shop_module')],
            },
        ),
        migrations.CreateModel(
            name='HullListing',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('featured', models.BooleanField(default=False)),
                ('featured_at', models.DateTimeField(blank=True, null=True)),
                ('price', models.PositiveBigIntegerField(default=0)),
                ('stock', models.PositiveIntegerField(default=0)),
                ('stock_mode', models.CharField(choices=[('auto', 'Auto'), ('fixed', 'Fixed')], default='auto', max_length=10)),
                ('price_mode', models.CharField(choices=[('fixed', 'Fixed'), ('jita_buy_pct', '% Jita Buy'), ('jita_sell_pct', '% Jita Sell')], default='fixed', max_length=20)),
                ('price_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
                ('persist', models.BooleanField(default=False)),
                ('description', models.TextField(blank=True, default='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('eve_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='eveuniverse.evetype')),
                ('shop', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='hull_listings', to='shop.shop')),
            ],
            options={
                'constraints': [models.UniqueConstraint(fields=('shop', 'eve_type'), name='uniq_shop_hull')],
            },
        ),
        migrations.AddConstraint(
            model_name='bpclisting',
            constraint=models.UniqueConstraint(fields=('shop', 'eve_type'), name='uniq_shop_bpc'),
        ),
        migrations.AddConstraint(
            model_name='shopsource',
            constraint=models.CheckConstraint(condition=models.Q(models.Q(('character_audit__isnull', False), ('corporation_audit__isnull', True)), models.Q(('character_audit__isnull', True), ('corporation_audit__isnull', False)), _connector='OR'), name='shopsource_exactly_one_owner'),
        ),
    ]
