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


class Migration(migrations.Migration):
    """Additive only: two new tables, nothing existing is altered or dropped."""

    dependencies = [
        ('marketplace', '0001_initial'),
        ('ecommerce', '0031_emaillog_is_archived'),
        ('pages', '0029_sitesettings_apple_touch_icon_consent'),
        ('tenants', '0017_modulelog_acquisition'),
        ('tickets', '0002_blockedemail'),
    ]

    operations = [
        migrations.CreateModel(
            name='Plugin',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('section', models.CharField(choices=[
                    ('server', 'Upgrading Server Quality'),
                    ('panel', 'Upgrading Panel and Modules'),
                    ('product', 'Products'),
                    ('service', 'Services'),
                    ('subscription', 'Subscriptions'),
                ], max_length=20)),
                ('fulfilment', models.CharField(choices=[
                    ('request', 'Request, then we invoice'),
                    ('online', 'Buy online, delivered within 24 hours'),
                    ('module', 'Buy online, switches on immediately'),
                ], default='request', max_length=20)),
                ('module_key', models.CharField(blank=True, help_text='Tenant module this unlocks, e.g. analytics or crm', max_length=40)),
                ('title_override', models.CharField(blank=True, max_length=150)),
                ('blurb', models.CharField(blank=True, help_text='One line shown on the plugin card', max_length=250)),
                ('price_override', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('price_label', models.CharField(blank=True, help_text='e.g. from £299 per month', max_length=60)),
                ('visible_plans', models.CharField(blank=True, help_text='Comma separated plan slugs. Blank means every plan sees it.', max_length=200)),
                ('is_active', models.BooleanField(default=True)),
                ('is_featured', models.BooleanField(default=False)),
                ('order', models.PositiveIntegerField(default=1)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('product', models.ForeignKey(blank=True, help_text='Covers products and subscriptions', null=True,
                                              on_delete=django.db.models.deletion.CASCADE,
                                              related_name='plugins', to='ecommerce.product')),
                ('service', models.ForeignKey(blank=True, null=True,
                                              on_delete=django.db.models.deletion.CASCADE,
                                              related_name='plugins', to='pages.service')),
            ],
            options={
                'verbose_name': 'Plugin',
                'verbose_name_plural': 'Plugins',
                'ordering': ['section', 'order', 'id'],
            },
        ),
        migrations.CreateModel(
            name='PluginRequest',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('plugin_title', models.CharField(help_text='Copied at request time so history survives catalogue edits', max_length=150)),
                ('section', models.CharField(blank=True, max_length=20)),
                ('requested_by', models.CharField(blank=True, help_text='Name or username on the tenant side', max_length=150)),
                ('message', models.TextField(blank=True)),
                ('status', models.CharField(choices=[
                    ('requested', 'Requested'),
                    ('accepted', 'Accepted'),
                    ('declined', 'Declined'),
                    ('billed', 'Invoiced'),
                    ('delivered', 'Delivered'),
                ], default='requested', max_length=20)),
                ('quoted_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('internal_note', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('decided_at', models.DateTimeField(blank=True, null=True)),
                ('delivered_at', models.DateTimeField(blank=True, null=True)),
                ('invoice', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
                                              related_name='plugin_requests', to='tenants.tenantinvoice')),
                ('plugin', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
                                             related_name='requests', to='marketplace.plugin')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                             related_name='plugin_requests', to='tenants.tenant')),
                ('ticket', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
                                             related_name='plugin_requests', to='tickets.ticket')),
            ],
            options={
                'verbose_name': 'Plugin Request',
                'verbose_name_plural': 'Plugin Requests',
                'ordering': ['-created_at'],
            },
        ),
    ]
