# Generated by Django 4.2.16 on 2025-06-16 16:22

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('ddm_questionnaire', '0011_alter_openquestion_options_and_more'),
    ]

    operations = [
        migrations.AddField(
            model_name='questionnaireresponse',
            name='questionnaire_config',
            field=models.JSONField(default=list, null=True),
        ),
        migrations.CreateModel(
            name='FilterCondition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source_type', models.CharField(choices=[('question', 'Question'), ('item', 'Question Item'), ('url_parameter', 'URL Parameter'), ('system', 'System Variable'), ('participant', 'Participant Variable'), ('donation', 'Donation Information')], max_length=60)),
                ('source_identifier', models.CharField(max_length=255, null=True)),
                ('index', models.IntegerField(default=1)),
                ('combinator', models.CharField(choices=[('AND', 'AND'), ('OR', 'OR')], default='AND', help_text='Defines whether all conditions (AND) or any (OR) must be met.In the filter condition with the lowest index, this will be ignored. The conditions following will be evaluated as a chain, where AND has higher precedence than OR. E.g., Condition1 OR Condition2 AND Condition3 OR Condition4 will be evaluated as "Condition1 OR (Condition2 AND Condition3) OR Condition4".', max_length=3)),
                ('condition_operator', models.CharField(choices=[('==', 'Equal (==)'), ('!=', 'Not Equal (!=)'), ('>', 'Greater than (>)'), ('<', 'Smaller than (<)'), ('>=', 'Greater than or equal (>=)'), ('<=', 'Smaller than or equal (<=)'), ('contains', 'Contains'), ('contains_not', 'Does not Contain')], default='==', help_text='The condition operator for filtering.', max_length=20)),
                ('condition_value', models.JSONField(blank=True, help_text="The value to compare the source's value against.", null=True)),
                ('source_exists', models.BooleanField(default=True)),
                ('source_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dependent_filters', to='ddm_questionnaire.questionitem')),
                ('source_question', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dependent_filters', to='ddm_questionnaire.questionbase')),
                ('target_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ddm_questionnaire.questionitem')),
                ('target_question', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ddm_questionnaire.questionbase')),
            ],
        ),
        migrations.AddConstraint(
            model_name='filtercondition',
            constraint=models.UniqueConstraint(fields=('target_item', 'target_question', 'index'), name='unique_index_per_target'),
        ),
    ]
