# Generated by Django 5.2 on 2025-12-04 00:00

from django.conf import settings
from django.db import migrations, models

from constants.plans import PlanNames, PlanNamesChoices


def seed_tool_config(apps, schema_editor):
    ToolConfig = apps.get_model("api", "ToolConfig")

    default_min_minutes = getattr(settings, "PERSISTENT_AGENT_MIN_SCHEDULE_MINUTES", 30)

    for plan_name in PlanNamesChoices.values:
        ToolConfig.objects.update_or_create(
            plan_name=plan_name,
            defaults={"min_cron_schedule_minutes": default_min_minutes},
        )


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0214_browserconfig'),
    ]

    operations = [
        migrations.CreateModel(
            name='ToolConfig',
            fields=[
                ('plan_name', models.CharField(choices=[('free', 'Free'), ('startup', 'Startup'), ('pln_l_m_v1', 'Scale'), ('org_team', 'Team')], help_text='Plan identifier the tool configuration applies to.', max_length=32, primary_key=True, serialize=False)),
                ('min_cron_schedule_minutes', models.PositiveIntegerField(default=30, help_text='Minimum allowed cron/interval frequency in minutes; set to 0 to disable enforcement.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Tool configuration',
                'verbose_name_plural': 'Tool configuration',
                'ordering': ['plan_name'],
            },
        ),
        migrations.RunPython(seed_tool_config, migrations.RunPython.noop),
    ]
