"""Pin the wallet Shop applet atop the wallet row.

The 4-applet wallet layout (per [[project-wallet-shop-expansion]]) wants
Shop first; the other 3 (Balances, Tokens, Payment) keep their historical
order via the default `display_order=100` + PK tie-break.

Idempotent — `update_or_create(slug=…, defaults={display_order: 10})`
also covers fresh DBs where `0011_seed_wallet_shop_applet` already ran.
"""
from django.db import migrations


def forward(apps, schema_editor):
    Applet = apps.get_model("applets", "Applet")
    Applet.objects.filter(slug="wallet-shop").update(display_order=10)


def reverse(apps, schema_editor):
    Applet = apps.get_model("applets", "Applet")
    Applet.objects.filter(slug="wallet-shop").update(display_order=100)


class Migration(migrations.Migration):

    dependencies = [
        ("applets", "0012_applet_display_order"),
    ]

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