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


def reorder_impact_types(apps, schema_editor):
    ImpactType = apps.get_model("incidents", "ImpactType")
    # On suppose que les valeurs sont :
    # business_impact, customers_impact, sellers_impact, employees_impact
    order_map = {
        "business_impact": 1,
        "customers_impact": 2,
        "sellers_impact": 3,
        "employees_impact": 4,
    }
    for value, order in order_map.items():
        impact_type = ImpactType.objects.filter(value=value).first()
        if impact_type:
            impact_type.order = order
            impact_type.save(update_fields=["order"])


class Migration(migrations.Migration):
    dependencies = [
        ("incidents", "0016_update_business_incidents_and_level"),
    ]
    operations = [
        migrations.RunPython(reorder_impact_types),
    ]
