# Generated by Django 4.2.9 on 2026-03-01 20:27

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


class Migration(migrations.Migration):

    dependencies = [
        ('app', '0090_tenantbillingevent_tenant_billing_grace_ends_at_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='TenantInvoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('invoice_number', models.CharField(max_length=48, unique=True)),
                ('period_start', models.DateTimeField(blank=True, null=True)),
                ('period_end', models.DateTimeField(blank=True, null=True)),
                ('issued_at', models.DateTimeField()),
                ('due_at', models.DateTimeField()),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('currency', models.CharField(default='USD', max_length=8)),
                ('status', models.CharField(choices=[('ISSUED', 'Issued'), ('OVERDUE', 'Overdue'), ('PAID', 'Paid'), ('VOID', 'Void'), ('CANCELED', 'Canceled')], default='ISSUED', max_length=20)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('source_event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='app.tenantbillingevent')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='app.tenant')),
            ],
            options={
                'db_table': 'app_tenant_invoice',
                'ordering': ('-issued_at', '-id'),
                'indexes': [models.Index(fields=['tenant', 'issued_at'], name='tenant_invoice_ti_idx'), models.Index(fields=['tenant', 'status'], name='tenant_invoice_ts_idx'), models.Index(fields=['due_at'], name='tenant_invoice_due_idx')],
            },
        ),
        migrations.AddConstraint(
            model_name='tenantinvoice',
            constraint=models.UniqueConstraint(fields=('tenant', 'due_at'), name='tenant_invoice_due_uniq'),
        ),
    ]
