# Generated by Django 5.2.8 on 2025-12-04 23:35

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


class Migration(migrations.Migration):

    dependencies = [
        ('billing', '0003_creditcostconfig'),
        ('igny8_core_auth', '0003_add_sync_event_model'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CreditPackage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('slug', models.SlugField(unique=True)),
                ('credits', models.IntegerField(validators=[django.core.validators.MinValueValidator(1)])),
                ('price', models.DecimalField(decimal_places=2, max_digits=10)),
                ('discount_percentage', models.IntegerField(default=0, help_text='Discount percentage (0-100)')),
                ('stripe_product_id', models.CharField(blank=True, max_length=255, null=True)),
                ('stripe_price_id', models.CharField(blank=True, max_length=255, null=True)),
                ('paypal_plan_id', models.CharField(blank=True, max_length=255, null=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('is_featured', models.BooleanField(default=False, help_text='Show as featured package')),
                ('description', models.TextField(blank=True)),
                ('features', models.JSONField(default=list, help_text='Bonus features or highlights')),
                ('sort_order', models.IntegerField(default=0, help_text='Display order (lower = first)')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'igny8_credit_packages',
                'ordering': ['sort_order', 'price'],
            },
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('invoice_number', models.CharField(db_index=True, max_length=50, unique=True)),
                ('subtotal', models.DecimalField(decimal_places=2, max_digits=10)),
                ('tax', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, max_digits=10)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending'), ('paid', 'Paid'), ('void', 'Void'), ('uncollectible', 'Uncollectible')], db_index=True, default='pending', max_length=20)),
                ('invoice_date', models.DateField(db_index=True)),
                ('due_date', models.DateField()),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('line_items', models.JSONField(default=list, help_text='Invoice line items: [{description, amount, quantity}]')),
                ('stripe_invoice_id', models.CharField(blank=True, max_length=255, null=True)),
                ('payment_method', models.CharField(blank=True, max_length=50, null=True)),
                ('notes', models.TextField(blank=True)),
                ('metadata', models.JSONField(default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('account', models.ForeignKey(db_column='tenant_id', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='igny8_core_auth.account')),
                ('subscription', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='igny8_core_auth.subscription')),
            ],
            options={
                'db_table': 'igny8_invoices',
                'ordering': ['-invoice_date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Payment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10)),
                ('currency', models.CharField(default='USD', max_length=3)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('processing', 'Processing'), ('succeeded', 'Succeeded'), ('failed', 'Failed'), ('refunded', 'Refunded'), ('cancelled', 'Cancelled')], db_index=True, default='pending', max_length=20)),
                ('payment_method', models.CharField(choices=[('stripe', 'Stripe (Credit/Debit Card)'), ('paypal', 'PayPal'), ('bank_transfer', 'Bank Transfer (Manual)'), ('local_wallet', 'Local Wallet (Manual)'), ('manual', 'Manual Payment')], db_index=True, max_length=50)),
                ('stripe_payment_intent_id', models.CharField(blank=True, max_length=255, null=True)),
                ('stripe_charge_id', models.CharField(blank=True, max_length=255, null=True)),
                ('paypal_order_id', models.CharField(blank=True, max_length=255, null=True)),
                ('paypal_capture_id', models.CharField(blank=True, max_length=255, null=True)),
                ('manual_reference', models.CharField(blank=True, help_text='Bank transfer reference, wallet transaction ID, etc.', max_length=255)),
                ('manual_notes', models.TextField(blank=True, help_text='Admin notes for manual payments')),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('processed_at', models.DateTimeField(blank=True, null=True)),
                ('failed_at', models.DateTimeField(blank=True, null=True)),
                ('refunded_at', models.DateTimeField(blank=True, null=True)),
                ('failure_reason', models.TextField(blank=True)),
                ('metadata', models.JSONField(default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('account', models.ForeignKey(db_column='tenant_id', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='igny8_core_auth.account')),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_payments', to=settings.AUTH_USER_MODEL)),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='billing.invoice')),
            ],
            options={
                'db_table': 'igny8_payments',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PaymentMethodConfig',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('country_code', models.CharField(db_index=True, help_text='ISO 2-letter country code (e.g., US, GB, IN)', max_length=2)),
                ('payment_method', models.CharField(choices=[('stripe', 'Stripe'), ('paypal', 'PayPal'), ('bank_transfer', 'Bank Transfer'), ('local_wallet', 'Local Wallet')], max_length=50)),
                ('is_enabled', models.BooleanField(default=True)),
                ('display_name', models.CharField(blank=True, max_length=100)),
                ('instructions', models.TextField(blank=True, help_text='Payment instructions for users')),
                ('bank_name', models.CharField(blank=True, max_length=255)),
                ('account_number', models.CharField(blank=True, max_length=255)),
                ('routing_number', models.CharField(blank=True, max_length=255)),
                ('swift_code', models.CharField(blank=True, max_length=255)),
                ('wallet_type', models.CharField(blank=True, help_text='E.g., PayTM, PhonePe, etc.', max_length=100)),
                ('wallet_id', models.CharField(blank=True, max_length=255)),
                ('sort_order', models.IntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Payment Method Configuration',
                'verbose_name_plural': 'Payment Method Configurations',
                'db_table': 'igny8_payment_method_config',
                'ordering': ['country_code', 'sort_order'],
                'unique_together': {('country_code', 'payment_method')},
            },
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['account', 'status'], name='igny8_invoi_tenant__4c2de3_idx'),
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['account', 'invoice_date'], name='igny8_invoi_tenant__5107b7_idx'),
        ),
        migrations.AddIndex(
            model_name='invoice',
            index=models.Index(fields=['invoice_number'], name='igny8_invoi_invoice_6f16b5_idx'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['account', 'status'], name='igny8_payme_tenant__62289b_idx'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['account', 'payment_method'], name='igny8_payme_tenant__7d34bb_idx'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['invoice', 'status'], name='igny8_payme_invoice_316f1c_idx'),
        ),
    ]
