# Generated by Django 5.2 on 2025-11-29 19:31

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

from constants.plans import PlanNames


def seed_browser_config(apps, schema_editor):
    BrowserConfig = apps.get_model("api", "BrowserConfig")

    default_steps = getattr(settings, "BROWSER_AGENT_MAX_STEPS", 100)
    default_daily = getattr(settings, "BROWSER_AGENT_DAILY_MAX_TASKS", 60)
    default_active = getattr(settings, "BROWSER_AGENT_MAX_ACTIVE_TASKS", 3)

    for plan_name in (PlanNames.FREE, PlanNames.STARTUP, PlanNames.SCALE, PlanNames.ORG_TEAM):
        BrowserConfig.objects.update_or_create(
            plan_name=plan_name,
            defaults={
                "max_browser_steps": default_steps,
                "max_browser_tasks": default_daily,
                "max_active_browser_tasks": default_active,
            },
        )


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0213_mcp_org_assignments'),
    ]

    operations = [
        migrations.CreateModel(
            name='BrowserConfig',
            fields=[
                ('plan_name', models.CharField(choices=[('free', 'Free'), ('startup', 'Startup'), ('pln_l_m_v1', 'Scale'), ('org_team', 'Team')], help_text='Plan identifier the browser limits apply to.', max_length=32, primary_key=True, serialize=False)),
                ('max_browser_steps', models.PositiveIntegerField(default=100, help_text='Maximum steps per browser task; set to 0 to use the system default.')),
                ('max_browser_tasks', models.PositiveIntegerField(default=60, help_text='Maximum browser tasks that can start each day; set to 0 for unlimited.')),
                ('max_active_browser_tasks', models.PositiveIntegerField(default=3, help_text='Maximum concurrently active browser tasks; set to 0 for unlimited.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Browser configuration',
                'verbose_name_plural': 'Browser configuration',
                'ordering': ['plan_name'],
            },
        ),
        migrations.RunPython(seed_browser_config, migrations.RunPython.noop),
    ]
