# Generated by Django 5.2.9 on 2026-01-06 17:00

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0005_add_application_error'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='RateLimitAlertConfig',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('metric_type', models.CharField(choices=[('block_rate', 'Block Rate'), ('total_requests', 'Total Requests'), ('unique_ips', 'Unique IPs'), ('function_specific', 'Function Specific')], db_index=True, help_text='Type of metric to monitor', max_length=50)),
                ('threshold_value', models.FloatField(help_text='Threshold value that triggers alert')),
                ('time_window_ms', models.IntegerField(help_text='Time window in milliseconds for measurement')),
                ('function_name', models.CharField(blank=True, help_text='Specific function to monitor (for function_specific metric type)', max_length=100, null=True)),
                ('enabled', models.BooleanField(db_index=True, default=True, help_text='Whether this config is active')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Rate Limit Alert Config',
                'verbose_name_plural': 'Rate Limit Alert Configs',
                'ordering': ['metric_type', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RateLimitAlert',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('metric_type', models.CharField(help_text='Type of metric', max_length=50)),
                ('metric_value', models.FloatField(help_text='Actual value that triggered the alert')),
                ('threshold_value', models.FloatField(help_text='Threshold that was exceeded')),
                ('time_window_ms', models.IntegerField(help_text='Time window of measurement')),
                ('function_name', models.CharField(blank=True, help_text='Function name if applicable', max_length=100, null=True)),
                ('alert_message', models.TextField(help_text='Descriptive alert message')),
                ('resolved_at', models.DateTimeField(blank=True, db_index=True, help_text='When this alert was resolved', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('resolved_by', models.ForeignKey(blank=True, help_text='Admin who resolved this alert', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_rate_limit_alerts', to=settings.AUTH_USER_MODEL)),
                ('config', models.ForeignKey(help_text='Configuration that triggered this alert', on_delete=django.db.models.deletion.CASCADE, related_name='alerts', to='core.ratelimitalertconfig')),
            ],
            options={
                'verbose_name': 'Rate Limit Alert',
                'verbose_name_plural': 'Rate Limit Alerts',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['metric_type', 'created_at'], name='core_rateli_metric__6fd63e_idx'), models.Index(fields=['resolved_at', 'created_at'], name='core_rateli_resolve_98c143_idx')],
            },
        ),
        migrations.CreateModel(
            name='SystemAlert',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('alert_type', models.CharField(choices=[('orphaned_images', 'Orphaned Images'), ('stale_submissions', 'Stale Submissions'), ('circular_dependency', 'Circular Dependency'), ('validation_error', 'Validation Error'), ('ban_attempt', 'Ban Attempt'), ('upload_timeout', 'Upload Timeout'), ('high_error_rate', 'High Error Rate'), ('database_connection', 'Database Connection'), ('memory_usage', 'Memory Usage'), ('queue_backup', 'Queue Backup')], db_index=True, help_text='Type of system alert', max_length=50)),
                ('severity', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, help_text='Alert severity level', max_length=20)),
                ('message', models.TextField(help_text='Human-readable alert message')),
                ('metadata', models.JSONField(blank=True, help_text='Additional context data for this alert', null=True)),
                ('resolved_at', models.DateTimeField(blank=True, db_index=True, help_text='When this alert was resolved', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('resolved_by', models.ForeignKey(blank=True, help_text='Admin who resolved this alert', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_system_alerts', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'System Alert',
                'verbose_name_plural': 'System Alerts',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['severity', 'created_at'], name='core_system_severit_bd3efd_idx'), models.Index(fields=['alert_type', 'created_at'], name='core_system_alert_t_10942e_idx'), models.Index(fields=['resolved_at', 'created_at'], name='core_system_resolve_9da33f_idx')],
            },
        ),
    ]
