# Generated by Django 6.0.1 on 2026-05-11 20:32

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 = [
        ('complaints', '0002_initial'),
        ('contenttypes', '0002_remove_content_type_name'),
        ('organizations', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PXSource',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('code', models.CharField(blank=True, default='', help_text='Unique code for API references', max_length=50, unique=True)),
                ('name_en', models.CharField(help_text='Source name in English', max_length=200)),
                ('name_ar', models.CharField(blank=True, help_text='Source name in Arabic', max_length=200)),
                ('description', models.TextField(blank=True, help_text='Detailed description')),
                ('source_type', models.CharField(choices=[('internal', 'Internal'), ('external', 'External'), ('partner', 'Partner'), ('government', 'Government'), ('other', 'Other')], db_index=True, default='internal', help_text='Type of source', max_length=50)),
                ('contact_email', models.EmailField(blank=True, help_text='Contact email for external sources', max_length=254)),
                ('contact_phone', models.CharField(blank=True, help_text='Contact phone for external sources', max_length=20)),
                ('is_active', models.BooleanField(db_index=True, default=True, help_text='Whether this source is active for selection')),
                ('metadata', models.JSONField(blank=True, default=dict, help_text='Additional metadata')),
                ('total_complaints', models.IntegerField(default=0, editable=False, help_text='Cached total complaints count')),
                ('total_inquiries', models.IntegerField(default=0, editable=False, help_text='Cached total inquiries count')),
            ],
            options={
                'verbose_name': 'PX Source',
                'verbose_name_plural': 'PX Sources',
                'ordering': ['name_en'],
                'indexes': [models.Index(fields=['is_active', 'name_en'], name='px_sources__is_acti_ea1b54_idx')],
            },
        ),
        migrations.CreateModel(
            name='SourceUser',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('is_active', models.BooleanField(db_index=True, default=True, help_text='Whether this source user is active')),
                ('can_create_complaints', models.BooleanField(default=True, help_text='User can create complaints from this source')),
                ('can_create_inquiries', models.BooleanField(default=True, help_text='User can create inquiries from this source')),
                ('can_create_observations', models.BooleanField(default=True, help_text='User can create observations from this source')),
                ('can_create_suggestions', models.BooleanField(default=True, help_text='User can create suggestions from this source')),
                ('hospital', models.ForeignKey(blank=True, help_text='Hospital this source user belongs to', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='source_users', to='organizations.hospital')),
                ('source', models.ForeignKey(help_text='Source managed by this user', on_delete=django.db.models.deletion.CASCADE, related_name='source_users', to='px_sources.pxsource')),
                ('user', models.OneToOneField(help_text='User who manages this source', on_delete=django.db.models.deletion.CASCADE, related_name='source_user_profile', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Source User',
                'verbose_name_plural': 'Source Users',
                'ordering': ['source__name_en'],
            },
        ),
        migrations.CreateModel(
            name='CommunicationRequest',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('patient_name', models.CharField(blank=True, max_length=200)),
                ('patient_phone', models.CharField(blank=True, max_length=20)),
                ('patient_mrn', models.CharField(blank=True, max_length=50, verbose_name='Patient MRN')),
                ('reason', models.CharField(choices=[('complaint_followup', 'Complaint Follow-up'), ('general_inquiry', 'General Inquiry'), ('feedback', 'Feedback Sharing'), ('urgent', 'Urgent Matter'), ('other', 'Other')], default='general_inquiry', max_length=30)),
                ('message', models.TextField(help_text='Message from the patient/source user to PX team')),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('contacted', 'Contacted'), ('resolved', 'Resolved'), ('closed', 'Closed')], db_index=True, default='pending', max_length=20)),
                ('contacted_at', models.DateTimeField(blank=True, help_text='When PX team contacted the patient', null=True)),
                ('resolution_notes', models.TextField(blank=True, help_text='Notes from PX team about the resolution')),
                ('resolved_as_object_id', models.UUIDField(blank=True, null=True)),
                ('contacted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contacted_communication_requests', to=settings.AUTH_USER_MODEL)),
                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='communication_requests', to='organizations.hospital')),
                ('resolved_as_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_communication_requests', to='contenttypes.contenttype')),
                ('source_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='communication_requests', to='px_sources.sourceuser')),
            ],
            options={
                'verbose_name': 'Communication Request',
                'verbose_name_plural': 'Communication Requests',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='SourceComplaint',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('reference_number', models.CharField(db_index=True, max_length=50, unique=True)),
                ('subject', models.CharField(max_length=300)),
                ('description', models.TextField()),
                ('patient_name', models.CharField(blank=True, max_length=200)),
                ('contact_phone', models.CharField(blank=True, max_length=20)),
                ('contact_email', models.EmailField(blank=True, max_length=254)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('status', models.CharField(choices=[('open', 'Open'), ('converted', 'Converted'), ('closed', 'Closed')], db_index=True, default='open', max_length=20)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_source_complaints', to=settings.AUTH_USER_MODEL)),
                ('px_source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='source_complaints', to='px_sources.pxsource')),
                ('system_complaint', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='source_complaint', to='complaints.complaint')),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['px_source', '-created_at'], name='px_sources__px_sour_6a780f_idx'), models.Index(fields=['status'], name='px_sources__status_352ef7_idx')],
            },
        ),
        migrations.CreateModel(
            name='SourceUsage',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('object_id', models.UUIDField(help_text='ID of related object')),
                ('content_type', models.ForeignKey(help_text='Type of related object', on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
                ('hospital', models.ForeignKey(blank=True, help_text='Hospital where this source was used', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='source_usage_records', to='organizations.hospital')),
                ('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='usage_records', to='px_sources.pxsource')),
                ('user', models.ForeignKey(blank=True, help_text='User who selected this source', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='source_usage_records', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Source Usage',
                'verbose_name_plural': 'Source Usages',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['source', '-created_at'], name='px_sources__source__13a9ae_idx'), models.Index(fields=['content_type', 'object_id'], name='px_sources__content_30cb33_idx'), models.Index(fields=['hospital', '-created_at'], name='px_sources__hospita_a0479a_idx'), models.Index(fields=['created_at'], name='px_sources__created_8606b0_idx')],
                'unique_together': {('content_type', 'object_id')},
            },
        ),
        migrations.AddIndex(
            model_name='sourceuser',
            index=models.Index(fields=['user', 'is_active'], name='px_sources__user_id_40a726_idx'),
        ),
        migrations.AddIndex(
            model_name='sourceuser',
            index=models.Index(fields=['source', 'is_active'], name='px_sources__source__eb51c5_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='sourceuser',
            unique_together={('user', 'source')},
        ),
        migrations.AddIndex(
            model_name='communicationrequest',
            index=models.Index(fields=['hospital', 'status', '-created_at'], name='px_sources__hospita_9551ab_idx'),
        ),
    ]
