# Generated by Django 5.2.1 on 2025-05-23 16:06

from django.db import migrations
from sites_conformes.events.models import EventEntryPage, EventsIndexPage
from itertools import chain


def migrate_obsolete_fields(apps, schema_editor):
    EventsIndexPage = apps.get_model("sites_conformes_events", "EventsIndexPage")
    EventEntryPage = apps.get_model("sites_conformes_events", "EventEntryPage")

    pages = chain(EventsIndexPage.objects.all(), EventEntryPage.objects.all())

    for page in pages:
        if not page.header_cta_label and not page.header_cta_link:
            continue

        if page.header_cta_buttons:
            continue

        button_block = (
            "button",
            {
                "text": page.header_cta_label,
                "button_type": "",
                "icon_class": "",
                "icon_side": "",
                "external_url": page.header_cta_link,
            },
        )

        page.header_cta_buttons = [("buttons", [button_block])]
        page.save()


class Migration(migrations.Migration):

    dependencies = [
        ("sites_conformes_events", "0017_alter_evententrypage_body_alter_eventsindexpage_body"),
    ]

    operations = []
