# Generated by Django 6.0.1 on 2026-01-15 12:02

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('complaints', '0002_initial'),
        ('organizations', '0001_initial'),
        ('px_sources', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name='complaint',
            name='source',
            field=models.ForeignKey(blank=True, help_text='Source of the complaint', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='complaints', to='px_sources.pxsource'),
        ),
        migrations.AddField(
            model_name='complaint',
            name='staff',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='complaints', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='complaintattachment',
            name='complaint',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='complaints.complaint'),
        ),
        migrations.AddField(
            model_name='complaintattachment',
            name='uploaded_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='complaint_attachments', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='complaintcategory',
            name='hospitals',
            field=models.ManyToManyField(blank=True, help_text='Empty list = system-wide category. Add hospitals to share category.', related_name='complaint_categories', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='complaintcategory',
            name='parent',
            field=models.ForeignKey(blank=True, help_text='Parent category for hierarchical structure', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='subcategories', to='complaints.complaintcategory'),
        ),
        migrations.AddField(
            model_name='complaint',
            name='category',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='complaints', to='complaints.complaintcategory'),
        ),
        migrations.AddField(
            model_name='complaintexplanation',
            name='complaint',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='explanations', to='complaints.complaint'),
        ),
        migrations.AddField(
            model_name='complaintexplanation',
            name='escalated_to_manager',
            field=models.ForeignKey(blank=True, help_text="Escalated to this explanation (manager's explanation request)", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='escalated_from_staff', to='complaints.complaintexplanation'),
        ),
        migrations.AddField(
            model_name='complaintexplanation',
            name='requested_by',
            field=models.ForeignKey(blank=True, help_text='User who requested the explanation', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='requested_complaint_explanations', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='complaintexplanation',
            name='staff',
            field=models.ForeignKey(blank=True, help_text='Staff member who submitted the explanation', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='complaint_explanations', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='complaintslaconfig',
            name='hospital',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='complaint_sla_configs', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='complaintthreshold',
            name='hospital',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='complaint_thresholds', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='complaintupdate',
            name='complaint',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='updates', to='complaints.complaint'),
        ),
        migrations.AddField(
            model_name='complaintupdate',
            name='created_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='complaint_updates', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='escalationrule',
            name='escalate_to_user',
            field=models.ForeignKey(blank=True, help_text="Specific user if escalate_to_role is 'specific_user'", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='escalation_target_rules', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='escalationrule',
            name='hospital',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='escalation_rules', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='explanationattachment',
            name='explanation',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='complaints.complaintexplanation'),
        ),
        migrations.AddField(
            model_name='explanationslaconfig',
            name='hospital',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='explanation_sla_configs', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='assigned_to',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_inquiries', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='department',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inquiries', to='organizations.department'),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='hospital',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inquiries', to='organizations.hospital'),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='patient',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='inquiries', to='organizations.patient'),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='responded_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='responded_inquiries', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='inquiry',
            name='source',
            field=models.ForeignKey(blank=True, help_text='Source of inquiry', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='inquiries', to='px_sources.pxsource'),
        ),
        migrations.AddField(
            model_name='inquiryattachment',
            name='inquiry',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='complaints.inquiry'),
        ),
        migrations.AddField(
            model_name='inquiryattachment',
            name='uploaded_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inquiry_attachments', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='inquiryupdate',
            name='created_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inquiry_updates', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='inquiryupdate',
            name='inquiry',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='updates', to='complaints.inquiry'),
        ),
        migrations.AddIndex(
            model_name='complaintcategory',
            index=models.Index(fields=['code'], name='complaints__code_8e9bbe_idx'),
        ),
        migrations.AddIndex(
            model_name='complaint',
            index=models.Index(fields=['status', '-created_at'], name='complaints__status_f077e8_idx'),
        ),
        migrations.AddIndex(
            model_name='complaint',
            index=models.Index(fields=['hospital', 'status', '-created_at'], name='complaints__hospita_cf53df_idx'),
        ),
        migrations.AddIndex(
            model_name='complaint',
            index=models.Index(fields=['is_overdue', 'status'], name='complaints__is_over_3d3554_idx'),
        ),
        migrations.AddIndex(
            model_name='complaint',
            index=models.Index(fields=['due_at', 'status'], name='complaints__due_at_836821_idx'),
        ),
        migrations.AddIndex(
            model_name='complaintexplanation',
            index=models.Index(fields=['complaint', '-created_at'], name='complaints__complai_b20e58_idx'),
        ),
        migrations.AddIndex(
            model_name='complaintexplanation',
            index=models.Index(fields=['token', 'is_used'], name='complaints__token_f8f9b7_idx'),
        ),
        migrations.AddIndex(
            model_name='complaintslaconfig',
            index=models.Index(fields=['hospital', 'is_active'], name='complaints__hospita_bdf8a5_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='complaintslaconfig',
            unique_together={('hospital', 'severity', 'priority')},
        ),
        migrations.AddIndex(
            model_name='complaintthreshold',
            index=models.Index(fields=['hospital', 'is_active'], name='complaints__hospita_b8efc9_idx'),
        ),
        migrations.AddIndex(
            model_name='complaintthreshold',
            index=models.Index(fields=['threshold_type', 'is_active'], name='complaints__thresho_719969_idx'),
        ),
        migrations.AddIndex(
            model_name='complaintupdate',
            index=models.Index(fields=['complaint', '-created_at'], name='complaints__complai_f3684e_idx'),
        ),
        migrations.AddIndex(
            model_name='escalationrule',
            index=models.Index(fields=['hospital', 'is_active'], name='complaints__hospita_3c8bac_idx'),
        ),
        migrations.AddIndex(
            model_name='explanationslaconfig',
            index=models.Index(fields=['hospital', 'is_active'], name='complaints__hospita_fe4ec5_idx'),
        ),
        migrations.AddIndex(
            model_name='inquiry',
            index=models.Index(fields=['status', '-created_at'], name='complaints__status_3d0678_idx'),
        ),
        migrations.AddIndex(
            model_name='inquiry',
            index=models.Index(fields=['hospital', 'status'], name='complaints__hospita_b1573b_idx'),
        ),
        migrations.AddIndex(
            model_name='inquiryupdate',
            index=models.Index(fields=['inquiry', '-created_at'], name='complaints__inquiry_551c37_idx'),
        ),
    ]
