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

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


class Migration(migrations.Migration):

    dependencies = [
        ('billing', '0001_initial_billing_models'),
        ('core', '0023_add_can_use_contracts_field'),
    ]

    operations = [
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('period_start', models.DateTimeField()),
                ('period_end', models.DateTimeField()),
                ('currency', models.CharField(default='USD', max_length=3)),
                ('subtotal_amount', models.PositiveIntegerField(default=0)),
                ('discount_amount', models.PositiveIntegerField(default=0)),
                ('tax_amount', models.PositiveIntegerField(default=0)),
                ('total_amount', models.PositiveIntegerField(default=0)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('open', 'Open'), ('paid', 'Paid'), ('void', 'Void'), ('refunded', 'Refunded')], default='draft', max_length=20)),
                ('plan_code_at_billing', models.CharField(blank=True, max_length=50)),
                ('plan_name_at_billing', models.CharField(blank=True, max_length=200)),
                ('plan_version_id_at_billing', models.PositiveIntegerField(blank=True, null=True)),
                ('billing_address_snapshot', models.JSONField(blank=True, default=dict)),
                ('tax_rate_snapshot', models.DecimalField(decimal_places=4, default=0, max_digits=5)),
                ('stripe_invoice_id', models.CharField(blank=True, max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('business', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='core.tenant')),
                ('subscription', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='billing.subscription')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='InvoiceLine',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('line_type', models.CharField(choices=[('plan', 'Plan Subscription'), ('addon', 'Add-On'), ('overage', 'Usage Overage'), ('credit', 'Credit'), ('adjustment', 'Adjustment')], max_length=20)),
                ('description', models.CharField(max_length=500)),
                ('quantity', models.PositiveIntegerField(default=1)),
                ('unit_amount', models.IntegerField(default=0)),
                ('subtotal_amount', models.IntegerField(default=0)),
                ('tax_amount', models.IntegerField(default=0)),
                ('total_amount', models.IntegerField(default=0)),
                ('feature_code', models.CharField(blank=True, max_length=100)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('addon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='billing.addonproduct')),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='billing.invoice')),
                ('plan_version', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='billing.planversion')),
            ],
            options={
                'ordering': ['id'],
            },
        ),
    ]
