# Generated by Django 4.2.4 on 2023-10-31 10:08
import i18nfield.fields
from django.db import migrations, models

import pretix.helpers.json


def convert_allowed_values(apps, schema_editor):
    EventMetaProperty = apps.get_model('pretixbase', 'EventMetaProperty')
    for emp in EventMetaProperty.objects.filter(allowed_values__isnull=False):
        emp.choices = [
            {"key": _v.strip(), "label": {"en": _v.strip()}}
            for _v in emp.allowed_values.splitlines()
        ]
        emp.save(update_fields=["choices"])


class Migration(migrations.Migration):
    dependencies = [
        ("pretixbase", "0249_hidden_if_item_available"),
    ]

    operations = [
        migrations.AddField(
            model_name="eventmetaproperty",
            name="filter_public",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="eventmetaproperty",
            name="public_label",
            field=i18nfield.fields.I18nCharField(null=True),
        ),
        migrations.AddField(
            model_name="eventmetaproperty",
            name="position",
            field=models.IntegerField(default=0),
        ),
        migrations.AddField(
            model_name="eventmetaproperty",
            name="choices",
            field=models.JSONField(null=True, encoder=pretix.helpers.json.CustomJSONEncoder),
        ),
        migrations.RunPython(
            convert_allowed_values,
            migrations.RunPython.noop
        ),
        migrations.RemoveField(
            model_name="eventmetaproperty",
            name="allowed_values",
        ),
    ]
