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


class Migration(migrations.Migration):

    dependencies = [
        ('tenants', '0010_tenantupgradecharge'),
    ]

    operations = [
        migrations.AddField(
            model_name='tenant',
            name='monthly_fee',
            field=models.DecimalField(decimal_places=2, default=0, help_text='Recurring monthly fee in GBP', max_digits=8),
        ),
        migrations.AddField(
            model_name='tenant',
            name='billing_day',
            field=models.PositiveSmallIntegerField(default=1, help_text='Day of month invoice is generated (1-28)'),
        ),
        migrations.AddField(
            model_name='tenant',
            name='next_renewal_date',
            field=models.DateField(blank=True, help_text='Date the next invoice is due', null=True),
        ),
        migrations.AddField(
            model_name='tenant',
            name='billing_email',
            field=models.EmailField(blank=True, help_text='Where invoices are sent (defaults to owner email)', max_length=254),
        ),
        migrations.CreateModel(
            name='TenantInvoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('invoice_number', models.CharField(blank=True, max_length=30, unique=True)),
                ('invoice_type', models.CharField(choices=[('monthly', 'Monthly Subscription'), ('setup', 'Setup / Onboarding Fee'), ('addon', 'Add-on / Extra')], default='monthly', max_length=20)),
                ('description', models.CharField(blank=True, max_length=300)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=8)),
                ('currency', models.CharField(default='GBP', max_length=3)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending'), ('paid', 'Paid'), ('overdue', 'Overdue'), ('cancelled', 'Cancelled')], default='pending', max_length=15)),
                ('due_date', models.DateField()),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('period_start', models.DateField(blank=True, null=True)),
                ('period_end', models.DateField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='tenants.tenant')),
            ],
            options={
                'verbose_name': 'Tenant Invoice',
                'verbose_name_plural': 'Tenant Invoices',
                'ordering': ['-created_at'],
            },
        ),
    ]
