# Generated by Django 4.0 on 2021-12-27 21:03
from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def update_title_for_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
    slug_title_map = {
        "default-provider-authorization-implicit-consent": "Redirecting to %(app)s",
        "default-provider-authorization-explicit-consent": "Redirecting to %(app)s",
    }
    db_alias = schema_editor.connection.alias
    Flow = apps.get_model("authentik_flows", "Flow")
    for flow in Flow.objects.using(db_alias).all():
        if flow.slug not in slug_title_map:
            continue
        flow.title = slug_title_map[flow.slug]
        flow.save()


class Migration(migrations.Migration):

    dependencies = [
        ("authentik_flows", "0020_flowtoken"),
    ]

    operations = [migrations.RunPython(update_title_for_defaults)]
