# Generated by Django 4.2.17 on 2024-12-31 13:40
from __future__ import annotations

from typing import TYPE_CHECKING

from django.db import migrations, models

if TYPE_CHECKING:
    from django.db.backends.base.schema import BaseDatabaseSchemaEditor
    from django.db.migrations.state import StateApps


def _change_dict_to_python(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
    db_alias = schema_editor.connection.alias
    model_type = apps.get_model("slack_messages", "SlackMessagingPolicy")
    model_type.objects.using(db_alias).filter(template_type="D").update(template_type="P")


def _revert_python_to_dict(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
    db_alias = schema_editor.connection.alias
    model_type = apps.get_model("slack_messages", "SlackMessagingPolicy")
    model_type.objects.using(db_alias).filter(template_type="P").update(template_type="D")


class Migration(migrations.Migration):
    dependencies = [
        ("slack_messages", "0004_slackmessagingpolicy_template_type"),
    ]

    operations = [
        migrations.AlterField(
            model_name="slackmessagingpolicy",
            name="template_type",
            field=models.CharField(
                choices=[("P", "Python"), ("DJ", "Django"), ("DI", "Django Inline"), ("?", "Unknown")],
                default="P",
                help_text="Type of message template.",
                max_length=2,
                verbose_name="Template type",
            ),
        ),
        migrations.RunPython(
            code=_change_dict_to_python,
            reverse_code=_revert_python_to_dict,
        ),
    ]
