# Generated by Django 5.2.8 on 2025-12-02 16:57

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0016_tenant_can_use_calendar_sync'),
    ]

    operations = [
        migrations.AlterField(
            model_name='tierlimit',
            name='feature_code',
            field=models.CharField(help_text="Feature code (e.g., 'MAX_RESOURCES', 'MAX_ADDITIONAL_USERS')", max_length=100),
        ),
        migrations.CreateModel(
            name='QuotaOverage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quota_type', models.CharField(choices=[('MAX_ADDITIONAL_USERS', 'Additional Users'), ('MAX_RESOURCES', 'Resources'), ('MAX_SERVICES', 'Services'), ('MAX_EMAIL_TEMPLATES', 'Email Templates'), ('MAX_AUTOMATED_TASKS', 'Automated Tasks')], help_text='Which quota limit was exceeded', max_length=50)),
                ('status', models.CharField(choices=[('ACTIVE', 'Active - Grace period in effect'), ('RESOLVED', 'Resolved - User reduced usage or upgraded'), ('ARCHIVED', 'Archived - Grace period expired, resources archived'), ('CANCELLED', 'Cancelled - Admin intervention')], default='ACTIVE', max_length=20)),
                ('current_usage', models.IntegerField(help_text='Usage count when overage was detected')),
                ('allowed_limit', models.IntegerField(help_text='New limit after plan change')),
                ('overage_amount', models.IntegerField(help_text='Number of items over the limit (usage - limit)')),
                ('grace_period_days', models.IntegerField(default=30, help_text='Number of days before auto-archive')),
                ('detected_at', models.DateTimeField(auto_now_add=True, help_text='When the overage was first detected')),
                ('grace_period_ends_at', models.DateTimeField(help_text='When the grace period expires')),
                ('initial_email_sent_at', models.DateTimeField(blank=True, help_text='When the initial overage notification was sent', null=True)),
                ('week_reminder_sent_at', models.DateTimeField(blank=True, help_text='When the 7-day warning was sent', null=True)),
                ('day_reminder_sent_at', models.DateTimeField(blank=True, help_text='When the 1-day warning was sent', null=True)),
                ('resolved_at', models.DateTimeField(blank=True, help_text='When the overage was resolved', null=True)),
                ('resolution_method', models.CharField(blank=True, choices=[('USER_ARCHIVED', 'User selected resources to archive'), ('USER_DELETED', 'User deleted excess resources'), ('USER_UPGRADED', 'User upgraded their plan'), ('AUTO_ARCHIVED', 'Auto-archived after grace period'), ('ADMIN_RESOLVED', 'Resolved by admin')], max_length=50, null=True)),
                ('archived_resource_ids', models.JSONField(blank=True, default=list, help_text='IDs of resources that were archived due to this overage')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quota_overages', to='core.tenant')),
            ],
            options={
                'ordering': ['-detected_at'],
                'indexes': [models.Index(fields=['tenant', 'status'], name='core_quotao_tenant__5f1a84_idx'), models.Index(fields=['grace_period_ends_at', 'status'], name='core_quotao_grace_p_8a39bd_idx')],
            },
        ),
    ]
