"""Re-balance the Tithe shop items' writs payout.

User-locked 2026-05-22: `tithe-1` drops 144 → 12 Writs, `tithe-5` drops
750 → 60 Writs. Description strings updated in lockstep so the tooltip
prose tracks the new numbers.

`granted_token_type`, `granted_count`, `price_cents`, `max_owned`,
`display_order` all unchanged. Only the writs grant + the description
text shift.
"""
from django.db import migrations


_UPDATES = [
    {
        "slug": "tithe-1",
        "description": "1 Tithe Token + 12 Writs",
        "granted_writs": 12,
    },
    {
        "slug": "tithe-5",
        "description": "5 Tithe Tokens + 60 Writs",
        "granted_writs": 60,
    },
]
_OLD = [
    {"slug": "tithe-1", "description": "1 Tithe Token + 144 Writs", "granted_writs": 144},
    {"slug": "tithe-5", "description": "5 Tithe Tokens + 750 Writs", "granted_writs": 750},
]


def _apply(apps, specs):
    ShopItem = apps.get_model("lyric", "ShopItem")
    for spec in specs:
        ShopItem.objects.filter(slug=spec["slug"]).update(
            description=spec["description"],
            granted_writs=spec["granted_writs"],
        )


def forward(apps, schema_editor):
    _apply(apps, _UPDATES)


def reverse(apps, schema_editor):
    _apply(apps, _OLD)


class Migration(migrations.Migration):

    dependencies = [
        ("lyric", "0009_seed_shop_items"),
    ]

    operations = [
        migrations.RunPython(forward, reverse),
    ]
