# Generated by Django 5.0.14 on 2026-01-08 06:56

import apps.observations.models
import django.db.models.deletion
import django.utils.timezone
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='ObservationCategory',
            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)),
                ('name_en', models.CharField(max_length=200, verbose_name='Name (English)')),
                ('name_ar', models.CharField(blank=True, max_length=200, verbose_name='Name (Arabic)')),
                ('description', models.TextField(blank=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('sort_order', models.IntegerField(default=0, help_text='Lower numbers appear first')),
                ('icon', models.CharField(blank=True, help_text='Bootstrap icon class', max_length=50)),
            ],
            options={
                'verbose_name': 'Observation Category',
                'verbose_name_plural': 'Observation Categories',
                'ordering': ['sort_order', 'name_en'],
            },
        ),
        migrations.CreateModel(
            name='Observation',
            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)),
                ('tracking_code', models.CharField(db_index=True, default=apps.observations.models.generate_tracking_code, help_text='Unique code for tracking this observation', max_length=20, unique=True)),
                ('title', models.CharField(blank=True, help_text='Optional short title', max_length=300)),
                ('description', models.TextField(help_text='Detailed description of the observation')),
                ('severity', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, default='medium', max_length=20)),
                ('location_text', models.CharField(blank=True, help_text='Where the issue was observed (building, floor, room, etc.)', max_length=500)),
                ('incident_datetime', models.DateTimeField(default=django.utils.timezone.now, help_text='When the issue was observed')),
                ('reporter_staff_id', models.CharField(blank=True, help_text='Optional staff ID of the reporter', max_length=50)),
                ('reporter_name', models.CharField(blank=True, help_text='Optional name of the reporter', max_length=200)),
                ('reporter_phone', models.CharField(blank=True, help_text='Optional phone number for follow-up', max_length=20)),
                ('reporter_email', models.EmailField(blank=True, help_text='Optional email for follow-up', max_length=254)),
                ('status', models.CharField(choices=[('new', 'New'), ('triaged', 'Triaged'), ('assigned', 'Assigned'), ('in_progress', 'In Progress'), ('resolved', 'Resolved'), ('closed', 'Closed'), ('rejected', 'Rejected'), ('duplicate', 'Duplicate')], db_index=True, default='new', max_length=20)),
                ('source', models.CharField(choices=[('staff_portal', 'Staff Portal'), ('web_form', 'Web Form'), ('mobile_app', 'Mobile App'), ('email', 'Email'), ('call_center', 'Call Center'), ('other', 'Other')], default='staff_portal', help_text='How the observation was submitted', max_length=50)),
                ('triaged_at', models.DateTimeField(blank=True, null=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('resolution_notes', models.TextField(blank=True)),
                ('closed_at', models.DateTimeField(blank=True, null=True)),
                ('action_id', models.UUIDField(blank=True, help_text='ID of linked PX Action if converted', null=True)),
                ('client_ip', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('assigned_department', models.ForeignKey(blank=True, help_text='Department responsible for handling this observation', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_observations', to='organizations.department')),
                ('assigned_to', models.ForeignKey(blank=True, help_text='User assigned to handle this observation', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_observations', to=settings.AUTH_USER_MODEL)),
                ('closed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='closed_observations', to=settings.AUTH_USER_MODEL)),
                ('hospital', models.ForeignKey(help_text='Hospital where observation was made', on_delete=django.db.models.deletion.CASCADE, related_name='observations', to='organizations.hospital')),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_observations', to=settings.AUTH_USER_MODEL)),
                ('staff', models.ForeignKey(blank=True, help_text='Staff member mentioned in observation', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='observations', to='organizations.staff')),
                ('triaged_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='triaged_observations', to=settings.AUTH_USER_MODEL)),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='observations', to='observations.observationcategory')),
            ],
            options={
                'ordering': ['-created_at'],
                'permissions': [('triage_observation', 'Can triage observations'), ('manage_categories', 'Can manage observation categories')],
            },
        ),
        migrations.CreateModel(
            name='ObservationAttachment',
            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)),
                ('file', models.FileField(help_text='Uploaded file', upload_to='observations/%Y/%m/%d/')),
                ('filename', models.CharField(blank=True, max_length=500)),
                ('file_type', models.CharField(blank=True, max_length=100)),
                ('file_size', models.IntegerField(default=0, help_text='File size in bytes')),
                ('description', models.CharField(blank=True, max_length=500)),
                ('observation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='observations.observation')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ObservationNote',
            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)),
                ('note', models.TextField()),
                ('is_internal', models.BooleanField(default=True, help_text='Internal notes are not visible to public')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='observation_notes', to=settings.AUTH_USER_MODEL)),
                ('observation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='observations.observation')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ObservationStatusLog',
            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)),
                ('from_status', models.CharField(blank=True, choices=[('new', 'New'), ('triaged', 'Triaged'), ('assigned', 'Assigned'), ('in_progress', 'In Progress'), ('resolved', 'Resolved'), ('closed', 'Closed'), ('rejected', 'Rejected'), ('duplicate', 'Duplicate')], max_length=20)),
                ('to_status', models.CharField(choices=[('new', 'New'), ('triaged', 'Triaged'), ('assigned', 'Assigned'), ('in_progress', 'In Progress'), ('resolved', 'Resolved'), ('closed', 'Closed'), ('rejected', 'Rejected'), ('duplicate', 'Duplicate')], max_length=20)),
                ('comment', models.TextField(blank=True, help_text='Optional comment about the status change')),
                ('changed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='observation_status_changes', to=settings.AUTH_USER_MODEL)),
                ('observation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='status_logs', to='observations.observation')),
            ],
            options={
                'verbose_name': 'Observation Status Log',
                'verbose_name_plural': 'Observation Status Logs',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['hospital', 'status', '-created_at'], name='observation_hospita_dcd21a_idx'),
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['status', '-created_at'], name='observation_status_2b5566_idx'),
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['severity', '-created_at'], name='observation_severit_ba73c0_idx'),
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['tracking_code'], name='observation_trackin_23f207_idx'),
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['assigned_department', 'status'], name='observation_assigne_33edad_idx'),
        ),
        migrations.AddIndex(
            model_name='observation',
            index=models.Index(fields=['assigned_to', 'status'], name='observation_assigne_83ab1c_idx'),
        ),
    ]
