# Generated by Django 6.0 on 2026-04-27 15:10

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0359_add_persistent_agent_planning_mode_flag'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='TrialPromo',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=120)),
                ('code_digest', models.CharField(db_index=True, max_length=64, unique=True)),
                ('code_label', models.CharField(blank=True, default='', help_text='Human-readable code label for admin and Stripe metadata.', max_length=80)),
                ('plan', models.CharField(choices=[('startup', 'Pro'), ('pln_l_m_v1', 'Scale')], default='startup', max_length=32)),
                ('trial_days', models.PositiveIntegerField(help_text='Stripe trials can be at most 730 days.', validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(730)])),
                ('payment_method_required', models.BooleanField(default=True)),
                ('no_payment_method_end_behavior', models.CharField(choices=[('create_invoice', 'Create invoice'), ('cancel', 'Cancel subscription'), ('pause', 'Pause subscription')], default='create_invoice', help_text='Applied only when payment method is not required. create_invoice lets the subscription become past_due and recoverable.', max_length=32)),
                ('repeat_trials_allowed', models.BooleanField(default=False, help_text='When enabled, this promo can ignore same-user prior trial/subscription history.')),
                ('trial_abuse_filtering_enabled', models.BooleanField(default=True)),
                ('trial_credit_amount', models.DecimalField(blank=True, decimal_places=3, help_text='Optional one-time task credit grant override for trial start.', max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('0.001'))])),
                ('max_redemptions', models.PositiveIntegerField(blank=True, help_text='Maximum completed promo redemptions for this shared code. Checkout starts are not counted until Stripe confirms completion.', null=True)),
                ('active_from', models.DateTimeField(blank=True, null=True)),
                ('active_until', models.DateTimeField(blank=True, null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('headline', models.CharField(blank=True, default='', max_length=160)),
                ('description', models.TextField(blank=True, default='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Trial promo',
                'verbose_name_plural': 'Trial promos',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['is_active', 'active_from', 'active_until'], name='trial_promo_active_idx'), models.Index(fields=['plan'], name='trial_promo_plan_idx')],
            },
        ),
        migrations.CreateModel(
            name='TrialPromoRedemption',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('status', models.CharField(choices=[('checkout_started', 'Checkout started'), ('checkout_completed', 'Checkout completed'), ('checkout_expired', 'Checkout expired'), ('checkout_failed', 'Checkout failed')], db_index=True, default='checkout_started', max_length=32)),
                ('event_id', models.CharField(db_index=True, max_length=255)),
                ('stripe_customer_id', models.CharField(blank=True, db_index=True, default='', max_length=255)),
                ('stripe_checkout_session_id', models.CharField(blank=True, max_length=255, null=True, unique=True)),
                ('stripe_subscription_id', models.CharField(blank=True, db_index=True, default='', max_length=255)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('checkout_started_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('checkout_completed_at', models.DateTimeField(blank=True, null=True)),
                ('checkout_expired_at', models.DateTimeField(blank=True, null=True)),
                ('checkout_failed_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('promo', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='redemptions', to='api.trialpromo')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='trial_promo_redemptions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Trial promo redemption',
                'verbose_name_plural': 'Trial promo redemptions',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['promo', 'status'], name='trial_redemp_promo_status_idx'), models.Index(fields=['user', 'promo'], name='trial_redemp_user_promo_idx')],
            },
        ),
    ]
