# Generated by Django 5.2.8 on 2025-12-10 07:30

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('core', '0023_add_can_use_contracts_field'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='AddOnProduct',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(db_index=True, max_length=50, unique=True)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('price_monthly_cents', models.PositiveIntegerField(default=0)),
                ('price_one_time_cents', models.PositiveIntegerField(default=0)),
                ('stripe_product_id', models.CharField(blank=True, max_length=100)),
                ('stripe_price_id', models.CharField(blank=True, max_length=100)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Feature',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(db_index=True, max_length=100, unique=True)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('feature_type', models.CharField(choices=[('boolean', 'Boolean'), ('integer', 'Integer Limit')], max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Plan',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(db_index=True, max_length=50, unique=True)),
                ('name', models.CharField(max_length=100)),
                ('description', models.TextField(blank=True)),
                ('display_order', models.PositiveIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
            ],
            options={
                'ordering': ['display_order', 'name'],
            },
        ),
        migrations.CreateModel(
            name='PlanVersion',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('version', models.PositiveIntegerField(default=1)),
                ('name', models.CharField(max_length=200)),
                ('is_public', models.BooleanField(default=True)),
                ('is_legacy', models.BooleanField(default=False)),
                ('starts_at', models.DateTimeField(blank=True, null=True)),
                ('ends_at', models.DateTimeField(blank=True, null=True)),
                ('price_monthly_cents', models.PositiveIntegerField(default=0)),
                ('price_yearly_cents', models.PositiveIntegerField(default=0)),
                ('stripe_product_id', models.CharField(blank=True, max_length=100)),
                ('stripe_price_id_monthly', models.CharField(blank=True, max_length=100)),
                ('stripe_price_id_yearly', models.CharField(blank=True, max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='versions', to='billing.plan')),
            ],
            options={
                'ordering': ['plan', '-version'],
                'unique_together': {('plan', 'version')},
            },
        ),
        migrations.CreateModel(
            name='Subscription',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('trial', 'Trial'), ('active', 'Active'), ('past_due', 'Past Due'), ('canceled', 'Canceled')], default='active', max_length=20)),
                ('started_at', models.DateTimeField(auto_now_add=True)),
                ('current_period_start', models.DateTimeField()),
                ('current_period_end', models.DateTimeField()),
                ('trial_ends_at', models.DateTimeField(blank=True, null=True)),
                ('canceled_at', models.DateTimeField(blank=True, null=True)),
                ('stripe_subscription_id', models.CharField(blank=True, max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('business', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='billing_subscription', to='core.tenant')),
                ('plan_version', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='billing.planversion')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='EntitlementOverride',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source', models.CharField(choices=[('manual', 'Manual Override'), ('promo', 'Promotional'), ('support', 'Support Grant')], max_length=20)),
                ('bool_value', models.BooleanField(blank=True, null=True)),
                ('int_value', models.PositiveIntegerField(blank=True, null=True)),
                ('reason', models.TextField(blank=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('business', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='entitlement_overrides', to='core.tenant')),
                ('granted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('feature', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billing.feature')),
            ],
            options={
                'ordering': ['-created_at'],
                'unique_together': {('business', 'feature')},
            },
        ),
        migrations.CreateModel(
            name='AddOnFeature',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('bool_value', models.BooleanField(blank=True, null=True)),
                ('int_value', models.PositiveIntegerField(blank=True, null=True)),
                ('addon', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='features', to='billing.addonproduct')),
                ('feature', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billing.feature')),
            ],
            options={
                'unique_together': {('addon', 'feature')},
            },
        ),
        migrations.CreateModel(
            name='PlanFeature',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('bool_value', models.BooleanField(blank=True, null=True)),
                ('int_value', models.PositiveIntegerField(blank=True, null=True)),
                ('feature', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billing.feature')),
                ('plan_version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='features', to='billing.planversion')),
            ],
            options={
                'unique_together': {('plan_version', 'feature')},
            },
        ),
        migrations.CreateModel(
            name='SubscriptionAddOn',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('trial', 'Trial'), ('active', 'Active'), ('canceled', 'Canceled')], default='active', max_length=20)),
                ('activated_at', models.DateTimeField(auto_now_add=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('canceled_at', models.DateTimeField(blank=True, null=True)),
                ('stripe_subscription_item_id', models.CharField(blank=True, max_length=100)),
                ('addon', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='billing.addonproduct')),
                ('subscription', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addons', to='billing.subscription')),
            ],
            options={
                'ordering': ['-activated_at'],
                'unique_together': {('subscription', 'addon')},
            },
        ),
    ]
