# Generated by Django 5.2.15 on 2026-07-05 15:16

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 = [
        ('customers', '0001_initial'),
        ('network', '0001_initial'),
        ('tenancy', '0002_auditlog'),
        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(max_length=50)),
                ('title', models.CharField(max_length=255)),
                ('description', models.TextField()),
                ('severity', models.CharField(choices=[('MINOR', 'Minor'), ('MAJOR', 'Major'), ('CRITICAL', 'Critical')], default='MINOR', max_length=20)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('INVESTIGATING', 'Investigating'), ('IDENTIFIED', 'Identified'), ('MONITORING', 'Monitoring'), ('RESOLVED', 'Resolved')], default='OPEN', max_length=30)),
                ('root_cause', models.TextField(blank=True)),
                ('resolution_notes', models.TextField(blank=True)),
                ('started_at', models.DateTimeField()),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_support_incidents', to=settings.AUTH_USER_MODEL)),
                ('network_node', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='incidents', to='network.networknode')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_support_incidents', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'support_incident',
                'ordering': ['-started_at', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='IncidentAffectedService',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('added_at', models.DateTimeField(auto_now_add=True)),
                ('incident', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='affected_services', to='support.incident')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('service_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='incident_impacts', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'support_incident_affected_service',
                'ordering': ['added_at'],
            },
        ),
        migrations.CreateModel(
            name='Complaint',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('complaint_number', models.CharField(max_length=50)),
                ('category', models.CharField(choices=[('CONNECTIVITY', 'Connectivity'), ('SPEED', 'Speed'), ('BILLING', 'Billing'), ('DEVICE', 'Device'), ('INSTALLATION', 'Installation'), ('OTHER', 'Other')], max_length=30)),
                ('priority', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], default='MEDIUM', max_length=20)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('IN_PROGRESS', 'In Progress'), ('RESOLVED', 'Resolved'), ('CLOSED', 'Closed')], default='OPEN', max_length=30)),
                ('subject', models.CharField(max_length=255)),
                ('description', models.TextField()),
                ('resolution_notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('closed_at', models.DateTimeField(blank=True, null=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_support_complaints', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='complaints', to='customers.customer')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_records', to='tenancy.organization')),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_support_complaints', to=settings.AUTH_USER_MODEL)),
                ('service_account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='complaints', to='customers.serviceaccount')),
            ],
            options={
                'db_table': 'support_complaint',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['organization', 'status'], name='complaint_org_status_idx'), models.Index(fields=['organization', 'priority'], name='complaint_org_priority_idx'), models.Index(fields=['organization', 'customer'], name='complaint_org_customer_idx'), models.Index(fields=['organization', 'service_account'], name='complaint_org_service_idx')],
                'constraints': [models.UniqueConstraint(fields=('organization', 'complaint_number'), name='unique_complaint_number_per_org')],
            },
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['organization', 'status'], name='incident_org_status_idx'),
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['organization', 'severity'], name='incident_org_severity_idx'),
        ),
        migrations.AddIndex(
            model_name='incident',
            index=models.Index(fields=['organization', 'network_node'], name='incident_org_node_idx'),
        ),
        migrations.AddConstraint(
            model_name='incident',
            constraint=models.UniqueConstraint(fields=('organization', 'incident_number'), name='unique_incident_number_per_org'),
        ),
        migrations.AddIndex(
            model_name='incidentaffectedservice',
            index=models.Index(fields=['organization', 'incident'], name='incident_service_org_inc_idx'),
        ),
        migrations.AddIndex(
            model_name='incidentaffectedservice',
            index=models.Index(fields=['organization', 'service_account'], name='incident_service_org_srv_idx'),
        ),
        migrations.AddConstraint(
            model_name='incidentaffectedservice',
            constraint=models.UniqueConstraint(fields=('incident', 'service_account'), name='unique_service_per_incident'),
        ),
    ]
