# Generated by Django 5.2.15 on 2026-07-07 15:14

from django.db import migrations

_OLD_CARGO_PCT = 100
_NEW_CARGO_PCT = 25


def relax_standard_cargo_pct(apps, schema_editor):
    """The built-in "Standard" preset's CARGO rule moves from a full 100% to a
    more realistic 25% - most doctrines don't expect every pilot to carry a
    full cargo hold of consumables. Only the seeded builtin is touched; a
    manager's own custom "Standard"-named policy (if any) is left alone."""
    CompliancePolicy = apps.get_model("fitcheck", "CompliancePolicy")
    PolicySlotRule = apps.get_model("fitcheck", "PolicySlotRule")
    policy = CompliancePolicy.objects.filter(name="Standard", is_builtin=True).first()
    if policy is None:
        return
    PolicySlotRule.objects.filter(policy=policy, section="CARGO").update(
        min_quantity_pct=_NEW_CARGO_PCT
    )


def restore_standard_cargo_pct(apps, schema_editor):
    CompliancePolicy = apps.get_model("fitcheck", "CompliancePolicy")
    PolicySlotRule = apps.get_model("fitcheck", "PolicySlotRule")
    policy = CompliancePolicy.objects.filter(name="Standard", is_builtin=True).first()
    if policy is None:
        return
    PolicySlotRule.objects.filter(policy=policy, section="CARGO").update(
        min_quantity_pct=_OLD_CARGO_PCT
    )


class Migration(migrations.Migration):

    dependencies = [
        ('fitcheck', '0034_retire_default_policy'),
    ]

    operations = [
        migrations.RunPython(relax_standard_cargo_pct, restore_standard_cargo_pct),
    ]
