# Generated by Django 5.0.11 on 2025-02-17 18:14

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("baseapp_ai_langkit_chats", "0003_chatprepromptedquestion"),
    ]

    def fix_existing_orders(apps, schema_editor):
        ChatPrePromptedQuestion = apps.get_model(
            "baseapp_ai_langkit_chats", "ChatPrePromptedQuestion"
        )
        questions = ChatPrePromptedQuestion.objects.order_by("id")

        for index, question in enumerate(questions):
            question.order = index
            question.save(update_fields=["order"])

    operations = [
        migrations.AlterModelOptions(
            name="chatprepromptedquestion",
            options={
                "ordering": ["order"],
                "verbose_name": "Chat Pre-Prompted Question",
                "verbose_name_plural": "Chat Pre-Prompted Questions",
            },
        ),
        migrations.AddField(
            model_name="chatprepromptedquestion",
            name="order",
            field=models.PositiveIntegerField(
                default=0,
                help_text="Order in which the pre-prompted question will be shown in the dropdown from top to bottom.",
            ),
            preserve_default=False,
        ),
        migrations.RunPython(fix_existing_orders),
    ]
