# Generated by Django 5.2 on 2026-02-10

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


def seed_default_intelligence_tier(apps, schema_editor):
    IntelligenceTier = apps.get_model("api", "IntelligenceTier")
    if IntelligenceTier.objects.filter(is_default=True).exists():
        return
    tier = IntelligenceTier.objects.filter(key="standard").first()
    if tier is None:
        return
    tier.is_default = True
    tier.save(update_fields=["is_default"])


class Migration(migrations.Migration):

    dependencies = [
        ("api", "0285_alter_persistentagentcompletion_completion_type"),
    ]

    operations = [
        migrations.AddField(
            model_name="intelligencetier",
            name="is_default",
            field=models.BooleanField(
                default=False,
                help_text="When enabled, this tier is used as the system default for new agents (clamped per plan).",
            ),
        ),
        migrations.AddConstraint(
            model_name="intelligencetier",
            constraint=models.UniqueConstraint(
                fields=("is_default",),
                condition=Q(is_default=True),
                name="unique_default_intelligence_tier",
            ),
        ),
        migrations.RunPython(seed_default_intelligence_tier, migrations.RunPython.noop),
    ]

