# Generated by Django 5.2.8 on 2025-12-04 06:25

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        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)),
                ('request_id', models.UUIDField(help_text='Per-request correlation ID')),
                ('incident_id', models.CharField(help_text='Public-facing incident ID returned to clients (e.g., INCIDENT-0001)', max_length=50, unique=True)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('ACKNOWLEDGED', 'Acknowledged'), ('RESOLVED', 'Resolved'), ('SUPPRESSED', 'Suppressed')], db_index=True, default='OPEN', max_length=20)),
                ('http_status', models.PositiveSmallIntegerField()),
                ('method', models.CharField(max_length=10)),
                ('path', models.TextField(db_index=True)),
                ('query_string', models.TextField(blank=True, null=True)),
                ('user_id', models.TextField(blank=True, db_index=True, null=True)),
                ('session_key', models.CharField(blank=True, max_length=64, null=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, db_index=True, null=True)),
                ('user_agent', models.TextField(blank=True, null=True)),
                ('headers', models.JSONField(default=dict)),
                ('body_preview', models.TextField(blank=True, null=True)),
                ('content_type', models.CharField(blank=True, max_length=255, null=True)),
                ('exception_class', models.CharField(blank=True, max_length=255, null=True)),
                ('exception_message', models.TextField(blank=True, null=True)),
                ('stacktrace', models.TextField(blank=True, null=True)),
                ('occurred_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('notes', models.TextField(blank=True, null=True)),
                ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), blank=True, default=list, size=None)),
                ('dedup_hash', models.CharField(db_index=True, max_length=64)),
                ('occurrence_count', models.IntegerField(default=1)),
            ],
            options={
                'ordering': ['-occurred_at'],
                'indexes': [models.Index(fields=['-occurred_at'], name='django_blac_occurre_95b060_idx'), models.Index(fields=['dedup_hash'], name='django_blac_dedup_h_633a2b_idx'), models.Index(fields=['status', '-occurred_at'], name='django_blac_status_a765ad_idx')],
                'constraints': [models.CheckConstraint(condition=models.Q(('status__in', ['OPEN', 'ACKNOWLEDGED', 'RESOLVED', 'SUPPRESSED'])), name='valid_status')],
            },
        ),
        migrations.CreateModel(
            name='RequestActivity',
            fields=[
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('method', models.CharField(max_length=10)),
                ('path', models.TextField()),
                ('full_path', models.TextField(blank=True)),
                ('http_status', models.IntegerField()),
                ('response_time_ms', models.FloatField(blank=True, null=True)),
                ('view_name', models.CharField(blank=True, max_length=255)),
                ('route_name', models.CharField(blank=True, max_length=255)),
                ('request_id', models.CharField(blank=True, db_index=True, max_length=64)),
                ('is_authenticated', models.BooleanField(default=False)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True)),
                ('object_id', models.CharField(blank=True, max_length=255)),
                ('request_headers', models.JSONField(blank=True, default=dict)),
                ('request_body', models.TextField(blank=True)),
                ('response_headers', models.JSONField(blank=True, default=dict)),
                ('response_body', models.TextField(blank=True)),
                ('action', models.CharField(blank=True, max_length=64)),
                ('instance_before', models.JSONField(blank=True, default=dict)),
                ('instance_after', models.JSONField(blank=True, default=dict)),
                ('instance_diff', models.JSONField(blank=True, default=dict)),
                ('custom_action', models.CharField(blank=True, max_length=128)),
                ('custom_payload', models.JSONField(blank=True, default=dict)),
                ('extra', models.JSONField(blank=True, default=dict)),
                ('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='request_activities', to='contenttypes.contenttype')),
                ('incident', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='activities', to='django_blackbox.incident')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='request_activities', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['created_at'], name='django_blac_created_a7ac16_idx'), models.Index(fields=['http_status'], name='django_blac_http_st_5b1499_idx'), models.Index(fields=['method', 'path'], name='django_blac_method_1dfbed_idx'), models.Index(fields=['user', 'created_at'], name='django_blac_user_id_fadc07_idx')],
            },
        ),
    ]
