"""Rename the billboard `my-contacts` applet to `my-buddies` (slug + name).

User.buddies M2M (lyric/0004) lands at the same time; the applet links
to the new /billboard/my-buddies/ page where the user manages their
buddy list. "Contacts" was a placeholder name from the original
billboard scaffold.
"""
from django.db import migrations


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


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


class Migration(migrations.Migration):

    dependencies = [
        ("applets", "0005_seed_pronouns_applet"),
    ]

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