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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('tenants', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('slug', models.SlugField(blank=True, max_length=220)),
                ('product_type', models.CharField(choices=[('service', 'Service Package'), ('domain', 'Domain Name'), ('product', 'Physical / Digital Product'), ('hosting', 'Hosting Plan'), ('subscription', 'Subscription / Retainer')], default='service', max_length=20)),
                ('billing_period', models.CharField(choices=[('one_time', 'One-time payment'), ('monthly', 'Monthly subscription'), ('annual', 'Annual subscription')], default='one_time', max_length=20)),
                ('short_description', models.CharField(blank=True, max_length=300)),
                ('description', models.TextField(blank=True, help_text='Full description shown on product page')),
                ('features', models.TextField(blank=True, help_text='One feature per line — displayed as bullet list')),
                ('price', models.DecimalField(decimal_places=2, help_text='Full price (GBP)', max_digits=10)),
                ('deposit_amount', models.DecimalField(blank=True, decimal_places=2, help_text='Deposit amount — if set, customers can pay this now and the balance later', max_digits=10, null=True)),
                ('compare_at_price', models.DecimalField(blank=True, decimal_places=2, help_text='Original / crossed-out price for showing a discount', max_digits=10, null=True)),
                ('tax_included', models.BooleanField(default=True, help_text='Is VAT included in the price?')),
                ('stripe_product_id', models.CharField(blank=True, max_length=100)),
                ('stripe_price_id', models.CharField(blank=True, max_length=100)),
                ('image', models.ImageField(blank=True, null=True, upload_to='products/')),
                ('icon_class', models.CharField(blank=True, help_text='FontAwesome class e.g. fa-solid fa-globe', max_length=100)),
                ('badge', models.CharField(blank=True, help_text='Badge text e.g. "Most Popular"', max_length=50)),
                ('sort_order', models.PositiveIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('is_featured', models.BooleanField(default=False)),
                ('domain_tld', models.CharField(blank=True, help_text='e.g. .co.uk — one TLD per product', max_length=20)),
                ('reg_years_default', models.PositiveSmallIntegerField(default=1, help_text='Default registration years')),
                ('disk_space', models.CharField(blank=True, help_text='e.g. 10 GB SSD', max_length=30)),
                ('bandwidth', models.CharField(blank=True, help_text='e.g. Unlimited', max_length=30)),
                ('domains_included', models.PositiveSmallIntegerField(blank=True, help_text='Number of domains included', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('tenant', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='products', to='tenants.tenant')),
            ],
            options={
                'verbose_name': 'Product',
                'verbose_name_plural': 'Products',
                'ordering': ['sort_order', 'name'],
            },
        ),
        migrations.CreateModel(
            name='Order',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('order_number', models.CharField(editable=False, max_length=20, unique=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('deposit_paid', 'Deposit Paid'), ('paid', 'Paid'), ('processing', 'Processing'), ('completed', 'Completed'), ('cancelled', 'Cancelled'), ('refunded', 'Refunded')], default='pending', max_length=20)),
                ('customer_name', models.CharField(max_length=150)),
                ('customer_email', models.EmailField(max_length=254)),
                ('customer_phone', models.CharField(blank=True, max_length=30)),
                ('customer_company', models.CharField(blank=True, max_length=150)),
                ('subtotal', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('amount_paid', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('stripe_session_id', models.CharField(blank=True, max_length=200)),
                ('stripe_payment_intent_id', models.CharField(blank=True, max_length=200)),
                ('is_deposit_order', models.BooleanField(default=False, help_text='True if this payment was a deposit')),
                ('customer_notes', models.TextField(blank=True)),
                ('internal_notes', models.TextField(blank=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('tenant', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='tenants.tenant')),
                ('parent_order', models.ForeignKey(blank=True, help_text='For balance payments, points to the original deposit order', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='balance_payments', to='ecommerce.order')),
            ],
            options={
                'verbose_name': 'Order',
                'verbose_name_plural': 'Orders',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='OrderItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('product_name', models.CharField(max_length=200)),
                ('product_type', models.CharField(blank=True, max_length=20)),
                ('quantity', models.PositiveSmallIntegerField(default=1)),
                ('unit_price', models.DecimalField(decimal_places=2, max_digits=10)),
                ('total_price', models.DecimalField(decimal_places=2, max_digits=10)),
                ('domain_name', models.CharField(blank=True, help_text='e.g. mybusiness.co.uk', max_length=255)),
                ('domain_tld', models.CharField(blank=True, max_length=20)),
                ('registration_years', models.PositiveSmallIntegerField(default=1)),
                ('custom_description', models.TextField(blank=True, help_text='For custom / manual line items')),
                ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='ecommerce.order')),
                ('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ecommerce.product')),
            ],
            options={
                'verbose_name': 'Order Item',
                'verbose_name_plural': 'Order Items',
            },
        ),
        migrations.CreateModel(
            name='DomainRegistration',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('domain_name', models.CharField(max_length=255)),
                ('tld', models.CharField(max_length=20)),
                ('registration_years', models.PositiveSmallIntegerField(default=1)),
                ('registrar', models.CharField(default='namecheap', max_length=50)),
                ('registrar_order_id', models.CharField(blank=True, max_length=100)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('registered', 'Registered'), ('failed', 'Failed'), ('expired', 'Expired'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('nameservers', models.TextField(blank=True, help_text='JSON list of nameservers')),
                ('error_message', models.TextField(blank=True)),
                ('registered_at', models.DateTimeField(blank=True, null=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('order_item', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='domain_registration', to='ecommerce.orderitem')),
            ],
            options={
                'verbose_name': 'Domain Registration',
                'verbose_name_plural': 'Domain Registrations',
            },
        ),
    ]
