# Generated by Django 5.2.11

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("corpuses", "0041_rename_agent_prompt_to_task_instructions"),
    ]

    operations = [
        migrations.RemoveConstraint(
            model_name="corpusaction",
            name="valid_action_type_configuration",
        ),
        migrations.AddConstraint(
            model_name="corpusaction",
            constraint=models.CheckConstraint(
                condition=(
                    # Fieldset only (no analyzer, no agent)
                    models.Q(
                        fieldset__isnull=False,
                        analyzer__isnull=True,
                        agent_config__isnull=True,
                    )
                    # Analyzer only (no fieldset, no agent)
                    | models.Q(
                        fieldset__isnull=True,
                        analyzer__isnull=False,
                        agent_config__isnull=True,
                    )
                    # Agent with config (requires non-empty task_instructions)
                    | (
                        models.Q(
                            fieldset__isnull=True,
                            analyzer__isnull=True,
                            agent_config__isnull=False,
                        )
                        & ~models.Q(task_instructions="")
                    )
                    # Lightweight agent: task_instructions only
                    | (
                        models.Q(
                            fieldset__isnull=True,
                            analyzer__isnull=True,
                            agent_config__isnull=True,
                        )
                        & ~models.Q(task_instructions="")
                    )
                ),
                name="valid_action_type_configuration",
            ),
        ),
    ]
