# Generated by Django 6.0.3 on 2026-05-11 20:25

from django.db import migrations
from envipy_additional_information import HalfLife, HalfLifeModel, HalfLifeWS

MAPPING = {
    "": HalfLifeModel.OTHER,
    "HS-SFO": HalfLifeModel.HS_SFO,
    "FOMC": HalfLifeModel.FOMC,
    "FOTC": HalfLifeModel.DFOP,
    "FMOC": HalfLifeModel.FOMC,
    "DFOP": HalfLifeModel.DFOP,
    "SFO + SFO": HalfLifeModel.SFO_SFO,
    "FOMC-SFO": HalfLifeModel.FOMC_SFO,
    "first order kinetics": HalfLifeModel.SFO,
    "SFOÂ²": HalfLifeModel.SFO,
    "HS": HalfLifeModel.HS,
    "top down": HalfLifeModel.OTHER,
    "SFO": HalfLifeModel.SFO,
    "First Order": HalfLifeModel.SFO,
    "SFO/SFO": HalfLifeModel.SFO_SFO,
    "FOMC + SFO": HalfLifeModel.FOMC_SFO,
    "true": HalfLifeModel.SFO,
    "SFO-SFO": HalfLifeModel.SFO_SFO,
    "DFOP-SFO": HalfLifeModel.DFOP_SFO,
}


def forward_func(apps, schema_editor):
    AdditionalInformation = apps.get_model("epdb", "AdditionalInformation")

    hls = AdditionalInformation.objects.filter(type="HalfLife")

    for hl in hls:
        data = hl.data
        data["model"] = MAPPING[data["model"]].value
        hl.data = HalfLife(**data).model_dump(mode="json")
        hl.save()

    hlws = AdditionalInformation.objects.filter(type="HalfLifeWS")

    for hl in hlws:
        data = hl.data
        data["model"] = MAPPING[data["model"]].value
        hl.data = HalfLifeWS(**data).model_dump(mode="json")
        hl.save()


class Migration(migrations.Migration):
    dependencies = [
        ("epdb", "0024_user_contacted"),
    ]

    operations = [
        migrations.RunPython(forward_func, reverse_code=migrations.RunPython.noop),
    ]
