# Generated by Django 5.2.11 on 2026-04-05 04:29

import datetime
import django.db.models.deletion
import subscriptions.models
from decimal import Decimal
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('companies', '0003_alter_plan_options_plan_display_order_plan_is_public_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='SaasPromoCode',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='Case-insensitive promo code', max_length=50, unique=True)),
                ('description', models.CharField(blank=True, max_length=300)),
                ('discount_type', models.CharField(choices=[('percentage', 'Percentage (%)'), ('fixed_amount', 'Fixed Amount (₦)')], default='percentage', max_length=15)),
                ('discount_value', models.DecimalField(decimal_places=2, max_digits=10)),
                ('valid_from', models.DateField(blank=True, null=True)),
                ('valid_until', models.DateField(blank=True, null=True)),
                ('max_usage', models.PositiveIntegerField(default=0, help_text='0 = unlimited')),
                ('usage_count', models.PositiveIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('allowed_plans', models.ManyToManyField(blank=True, related_name='saas_promos', to='companies.plan')),
            ],
            options={
                'verbose_name': 'SaaS Promo Code',
                'verbose_name_plural': 'SaaS Promo Codes',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Subscription',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('billing_cycle', models.CharField(choices=[('monthly', 'Monthly (30 days)'), ('bimonthly', 'Every 2 Months (60 days)'), ('trimonthly', 'Every 3 Months (90 days)'), ('yearly', 'Yearly (365 days)')], default='monthly', max_length=15)),
                ('start_date', models.DateField(default=datetime.date.today)),
                ('expiry_date', models.DateField(blank=True, null=True)),
                ('is_trial', models.BooleanField(default=False)),
                ('is_active', models.BooleanField(default=True)),
                ('payment_status', models.CharField(choices=[('pending', 'Pending'), ('paid', 'Paid'), ('failed', 'Failed'), ('trial', 'Trial')], default='trial', max_length=10)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subscriptions', to='companies.company')),
                ('pending_downgrade_plan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pending_downgrades', to='companies.plan')),
                ('plan', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='subscriptions', to='companies.plan')),
            ],
            options={
                'verbose_name': 'Subscription',
                'verbose_name_plural': 'Subscriptions',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PaymentTransaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('billing_cycle', models.CharField(choices=[('monthly', 'Monthly (30 days)'), ('bimonthly', 'Every 2 Months (60 days)'), ('trimonthly', 'Every 3 Months (90 days)'), ('yearly', 'Yearly (365 days)')], default='monthly', max_length=15)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('discount_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=12)),
                ('final_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=12)),
                ('payment_reference', models.CharField(default=subscriptions.models._generate_reference, max_length=50, unique=True)),
                ('monnify_reference', models.CharField(blank=True, max_length=200)),
                ('promo_code_used', models.CharField(blank=True, max_length=50)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('paid', 'Paid'), ('failed', 'Failed'), ('cancelled', 'Cancelled')], default='pending', max_length=15)),
                ('payment_method', models.CharField(blank=True, max_length=50)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('raw_webhook_payload', models.JSONField(blank=True, default=dict)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payment_transactions', to='companies.company')),
                ('plan', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='companies.plan')),
                ('subscription', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions', to='subscriptions.subscription')),
            ],
            options={
                'verbose_name': 'Payment Transaction',
                'verbose_name_plural': 'Payment Transactions',
                'ordering': ['-created_at'],
            },
        ),
    ]
