# Generated by Django 4.2.20 on 2025-05-30 07:38
from django.db import migrations
from django.conf import settings
from oxyan.themes.definitions import theme


def forward(apps, schema_editor):
    StyleSettings = apps.get_model('coyote', 'StyleSettings')

    valid_options = getattr(settings, 'OXYAN_HEADER_OPTIONS', [])
    valid_option_values = [option[0] for option in valid_options] if valid_options else []

    theme_default = theme.get("header", "basic")
    if theme_default not in valid_option_values and valid_option_values:
        theme_default = "basic"

    for style_setting in StyleSettings.objects.all():
        if style_setting.header and style_setting.header not in valid_option_values:
            style_setting.header = theme_default
            style_setting.save()


class Migration(migrations.Migration):
    dependencies = [
        ('coyote', '0020_stylesettings_header'),
    ]

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