"""Seed the 3 starting catalog items for the wallet Shop applet.

Locked spec from [[project-wallet-shop-expansion]]:
    tithe-1 — $1   → 1 × TITHE + 144 writs (no cap)
    tithe-5 — $4   → 5 × TITHE + 750 writs (no cap; badge "×5")
    band-1  — $20  → 1 × BAND  + 0 writs   (max_owned=1)

Pricing migration-safe — admin can still adjust via Django admin without
needing a code change; this is the floor / initial offer.
"""

from django.db import migrations


SHOP_ITEMS = [
    {
        "slug": "tithe-1",
        "name": "Tithe Token",
        "description": "1 Tithe Token + 144 Writs",
        "icon": "fa-piggy-bank",
        "badge_text": "",
        "price_cents": 100,
        "granted_token_type": "tithe",
        "granted_count": 1,
        "granted_writs": 144,
        "max_owned": None,
        "display_order": 10,
    },
    {
        "slug": "tithe-5",
        "name": "Tithe Bundle",
        "description": "5 Tithe Tokens + 750 Writs",
        "icon": "fa-piggy-bank",
        "badge_text": "×5",
        "price_cents": 400,
        "granted_token_type": "tithe",
        "granted_count": 5,
        "granted_writs": 750,
        "max_owned": None,
        "display_order": 20,
    },
    {
        "slug": "band-1",
        "name": "Wristband",
        "description": "Admit All Entry — unlimited free entry (BYOB)",
        "icon": "fa-ring",
        "badge_text": "",
        "price_cents": 2000,
        "granted_token_type": "band",
        "granted_count": 1,
        "granted_writs": 0,
        "max_owned": 1,
        "display_order": 30,
    },
]


def seed_forward(apps, schema_editor):
    ShopItem = apps.get_model("lyric", "ShopItem")
    for spec in SHOP_ITEMS:
        ShopItem.objects.update_or_create(
            slug=spec["slug"],
            defaults={k: v for k, v in spec.items() if k != "slug"},
        )


def seed_reverse(apps, schema_editor):
    ShopItem = apps.get_model("lyric", "ShopItem")
    ShopItem.objects.filter(slug__in=[s["slug"] for s in SHOP_ITEMS]).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("lyric", "0008_shopitem_purchase"),
    ]

    operations = [
        migrations.RunPython(seed_forward, seed_reverse),
    ]
