# Generated by Django 5.1.4 on 2024-11-08 09:31
#
# Import of the 2024 campaign catalogue. Marketing sent it as a spreadsheet;
# this is the importer we ran against it, kept as a migration so a rebuilt
# environment comes up with the same catalogue as production.

from django.db import migrations

CAMPAIGNS = 210
TIERS_PER_CAMPAIGN = 60


def catalogue_rows():
    """The (campaign, tier) grid the export contained, in file order."""

    for campaign in range(1, CAMPAIGNS + 1):
        campaign_key = f"CMP-{campaign:04d}"
        for tier in range(1, TIERS_PER_CAMPAIGN + 1):
            yield campaign_key, f"T{tier:02d}"


def import_catalogue(apps, schema_editor):
    entry_model = apps.get_model("adjustments", "PromotionCatalogEntry")
    alias = schema_editor.connection.alias
    for campaign_key, tier_key in catalogue_rows():
        entry_model.objects.using(alias).create(
            entry_key=f"{campaign_key}:{tier_key}",
            campaign_key=campaign_key,
            tier_key=tier_key,
        )


class Migration(migrations.Migration):

    dependencies = [
        ("adjustments", "0002_promotioncatalogentry"),
    ]

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