# Generated by ChatGPT on 2024-06-24
from django.db import migrations


def update_impactlevel_names(apps, schema_editor):
    ImpactType = apps.get_model("incidents", "ImpactType")
    ImpactLevel = apps.get_model("incidents", "ImpactLevel")

    # Map: (impact_type.value, impact_level.value) -> new name
    updates = {
        ("business_impact", "HT"): "Critical Impact (>5% BV loss)",
        ("business_impact", "HI"): "Major Impact (<5% BV loss)",
        ("business_impact", "MD"): "Uncertain Business Impact",
        ("business_impact", "LO"): "Low Impact not measurable",
        ("business_impact", "LT"): "Very Low Impact not measurable",
        ("customers_impact", "HT"): "Critical issue for many customers",
        ("customers_impact", "HI"): "Major issue for many customers",
        ("customers_impact", "MD"): "Major issue for few customers",
        ("customers_impact", "LO"): "Minor issue for customers",
        ("customers_impact", "LT"): "Cosmetic minor issue for customers",
        ("sellers_impact", "HT"): "Critical issue for many sellers",
        ("sellers_impact", "HI"): "Major issue for many sellers",
        ("sellers_impact", "MD"): "Major issue for few sellers",
        ("sellers_impact", "LO"): "Minor issue for sellers",
        ("sellers_impact", "LT"): "Cosmetic minor issue for sellers",
        ("employees_impact", "MD"): "Departments fully blocked",
        ("employees_impact", "LO"): "Some employees affected",
        ("employees_impact", "LT"): "Degraded service for employees",
        ("employees_impact", "NO"): "No impact for employees",
    }

    for (impact_type_value, level_value), new_name in updates.items():
        impact_type = ImpactType.objects.filter(value=impact_type_value).first()
        if not impact_type:
            continue
        impact_level = ImpactLevel.objects.filter(impact_type=impact_type, value=level_value).first()
        if impact_level:
            impact_level.name = new_name
            impact_level.save(update_fields=["name"])


class Migration(migrations.Migration):
    dependencies = [
        ("incidents", "0017_reorder_impact_types"),
    ]
    operations = [
        migrations.RunPython(update_impactlevel_names),
    ]
