import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('organizations', '0003_alter_department_champion'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='Location',
            new_name='LegacyLocation',
        ),
        migrations.RenameModel(
            old_name='MainSection',
            new_name='LegacyMainSection',
        ),
        migrations.RenameModel(
            old_name='SubSection',
            new_name='LegacySubSection',
        ),
        migrations.AlterModelOptions(
            name='department',
            options={'ordering': ['hospital', 'area', 'name_en']},
        ),
        migrations.AddField(
            model_name='department',
            name='area',
            field=models.CharField(blank=True, db_index=True, help_text='High-level area (Medical, Administrative, Nursing, Support Services)', max_length=100),
        ),
        migrations.AddField(
            model_name='department',
            name='champion_email',
            field=models.EmailField(blank=True, help_text='Fallback email for champion', max_length=200),
        ),
        migrations.AddField(
            model_name='department',
            name='deputy_manager',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_deputy_manager', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='department',
            name='deputy_supervisor',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_deputy_supervisor', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='department',
            name='floor',
            field=models.CharField(blank=True, help_text='Floor (e.g., GF, 1st Floor, Basement)', max_length=50),
        ),
        migrations.AddField(
            model_name='department',
            name='location_type',
            field=models.CharField(blank=True, help_text='Location type (OP, IP, ER, GENERAL)', max_length=20),
        ),
        migrations.AddField(
            model_name='department',
            name='main_section',
            field=models.CharField(blank=True, help_text='Main section name (often same as department name)', max_length=200),
        ),
        migrations.AddField(
            model_name='department',
            name='manager_1st',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_manager_1st', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='department',
            name='manager_2nd',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_manager_2nd', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='department',
            name='manager_3rd',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_manager_3rd', to='organizations.staff'),
        ),
        migrations.AddField(
            model_name='department',
            name='old_name_ar',
            field=models.CharField(blank=True, help_text='Legacy Arabic name from Excel col X', max_length=200),
        ),
        migrations.AddField(
            model_name='department',
            name='old_name_en',
            field=models.CharField(blank=True, help_text='Legacy English name from Excel col W', max_length=200),
        ),
        migrations.AddField(
            model_name='department',
            name='sub_location',
            field=models.CharField(blank=True, help_text='Detailed location (e.g., OPD5/GATE1)', max_length=200),
        ),
        migrations.AddField(
            model_name='department',
            name='supervisor',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dept_supervisor', to='organizations.staff'),
        ),
        migrations.AlterField(
            model_name='department',
            name='category',
            field=models.CharField(blank=True, choices=[('nursing', 'Nursing'), ('support_services', 'Support Services'), ('medical', 'Medical'), ('non_medical', 'Non-Medical'), ('administrative', 'Administrative')], db_index=True, default='', max_length=30),
        ),
        migrations.AlterField(
            model_name='staff',
            name='department_type',
            field=models.CharField(blank=True, choices=[('nursing', 'Nursing'), ('support_services', 'Support Services'), ('medical', 'Medical'), ('non_medical', 'Non-Medical'), ('administrative', 'Administrative')], db_index=True, default='', max_length=30),
        ),
        migrations.CreateModel(
            name='OrgSubSection',
            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)),
                ('name_ar', models.CharField(blank=True, max_length=200)),
                ('code', models.CharField(blank=True, max_length=50)),
                ('location_type', models.CharField(blank=True, max_length=20)),
                ('sub_location', models.CharField(blank=True, max_length=200)),
                ('floor', models.CharField(blank=True, max_length=50)),
                ('old_name_en', models.CharField(blank=True, max_length=200)),
                ('old_name_ar', models.CharField(blank=True, max_length=200)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='org_subsections', to='organizations.department')),
                ('point_of_contact', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='poc_org_subsections', to='organizations.staff')),
            ],
            options={
                'verbose_name': 'Section',
                'verbose_name_plural': 'Sections',
                'ordering': ['department', 'name_en'],
                'unique_together': {('department', 'code')},
            },
        ),
        migrations.CreateModel(
            name='OrgSubSubSection',
            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)),
                ('name_ar', models.CharField(blank=True, max_length=200)),
                ('code', models.CharField(blank=True, max_length=50)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('subsection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sub_subsections', to='organizations.orgsubsection')),
            ],
            options={
                'verbose_name': 'Sub-Section',
                'verbose_name_plural': 'Sub-Sections',
                'ordering': ['subsection', 'name_en'],
                'unique_together': {('subsection', 'code')},
            },
        ),
        migrations.CreateModel(
            name='LegacyHierarchyMapping',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('old_location_ar', models.CharField(db_index=True, max_length=200)),
                ('old_main_section_ar', models.CharField(db_index=True, max_length=200)),
                ('old_subsection_ar', models.CharField(db_index=True, max_length=200)),
                ('old_location_en', models.CharField(blank=True, max_length=200)),
                ('old_main_section_en', models.CharField(blank=True, max_length=200)),
                ('old_subsection_en', models.CharField(blank=True, max_length=200)),
                ('main_section', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='legacy_mappings', to='organizations.department')),
                ('subsection', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='legacy_mappings', to='organizations.orgsubsection')),
                ('sub_subsection', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='legacy_mappings', to='organizations.orgsubsubsection')),
            ],
        ),
        migrations.AddIndex(
            model_name='legacyhierarchymapping',
            index=models.Index(fields=['old_location_ar', 'old_main_section_ar', 'old_subsection_ar'], name='organizatio_old_loc_920b0f_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='legacyhierarchymapping',
            unique_together={('old_location_ar', 'old_main_section_ar', 'old_subsection_ar')},
        ),
    ]
