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

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0006_add_alert_models'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Incident',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('incident_number', models.CharField(db_index=True, help_text='Auto-generated incident number (INC-YYYYMMDD-XXXX)', max_length=20, unique=True)),
                ('title', models.CharField(help_text='Brief description of the incident', max_length=255)),
                ('description', models.TextField(blank=True, help_text='Detailed description', null=True)),
                ('severity', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, help_text='Incident severity level', max_length=20)),
                ('status', models.CharField(choices=[('open', 'Open'), ('investigating', 'Investigating'), ('resolved', 'Resolved'), ('closed', 'Closed')], db_index=True, default='open', help_text='Current incident status', max_length=20)),
                ('detected_at', models.DateTimeField(auto_now_add=True, help_text='When the incident was detected')),
                ('acknowledged_at', models.DateTimeField(blank=True, help_text='When someone started investigating', null=True)),
                ('resolved_at', models.DateTimeField(blank=True, help_text='When the incident was resolved', null=True)),
                ('resolution_notes', models.TextField(blank=True, help_text='Notes about the resolution', null=True)),
                ('alert_count', models.PositiveIntegerField(default=0, help_text='Number of linked alerts')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('acknowledged_by', models.ForeignKey(blank=True, help_text='User who acknowledged the incident', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='acknowledged_incidents', to=settings.AUTH_USER_MODEL)),
                ('resolved_by', models.ForeignKey(blank=True, help_text='User who resolved the incident', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_incidents', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Incident',
                'verbose_name_plural': 'Incidents',
                'ordering': ['-detected_at'],
            },
        ),
        migrations.CreateModel(
            name='IncidentAlert',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('alert_source', models.CharField(choices=[('system', 'System Alert'), ('rate_limit', 'Rate Limit Alert')], help_text='Source type of the alert', max_length=20)),
                ('alert_id', models.UUIDField(help_text='ID of the linked alert')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('incident', models.ForeignKey(help_text='The incident this alert is linked to', on_delete=django.db.models.deletion.CASCADE, related_name='linked_alerts', to='core.incident')),
            ],
            options={
                'verbose_name': 'Incident Alert',
                'verbose_name_plural': 'Incident Alerts',
            },
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['status', 'detected_at'], name='core_incide_status_c17ea4_idx'),
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['severity', 'detected_at'], name='core_incide_severit_24b148_idx'),
        ),
        migrations.AddIndex(
            model_name='incidentalert',
            index=models.Index(fields=['alert_source', 'alert_id'], name='core_incide_alert_s_9e655c_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='incidentalert',
            unique_together={('incident', 'alert_source', 'alert_id')},
        ),
    ]
