"""Backfill super-schizo and super-nomad Notes for all existing superusers."""
from django.db import migrations
from django.utils import timezone


def grant_super_notes(apps, schema_editor):
    User = apps.get_model("lyric", "User")
    Note = apps.get_model("drama", "Note")
    now = timezone.now()
    for user in User.objects.filter(is_superuser=True):
        for slug in ("super-schizo", "super-nomad"):
            Note.objects.get_or_create(
                user=user, slug=slug,
                defaults={"earned_at": now},
            )


class Migration(migrations.Migration):

    dependencies = [
        ("drama", "0002_initial"),
        ("lyric", "0001_initial"),
    ]

    operations = [
        migrations.RunPython(grant_super_notes, migrations.RunPython.noop),
    ]
