"""Rename the My Buddies applet → My Buds (slug + name).

UI-vocabulary tightening — see lyric/0005_rename_buddies_to_buds for the
parallel User.buddies → User.buds field rename. BILLBUDDIES overflowed
the page-header band; BILLBUDS fits cleanly.
"""
from django.db import migrations


def forward(apps, schema_editor):
    Applet = apps.get_model("applets", "Applet")
    try:
        applet = Applet.objects.get(slug="my-buddies")
    except Applet.DoesNotExist:
        return
    applet.slug = "my-buds"
    applet.name = "My Buds"
    applet.save(update_fields=["slug", "name"])


def backward(apps, schema_editor):
    Applet = apps.get_model("applets", "Applet")
    try:
        applet = Applet.objects.get(slug="my-buds")
    except Applet.DoesNotExist:
        return
    applet.slug = "my-buddies"
    applet.name = "My Buddies"
    applet.save(update_fields=["slug", "name"])


class Migration(migrations.Migration):

    dependencies = [
        ("applets", "0006_rename_contacts_to_buddies"),
    ]

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