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

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0222_browseruseagenttask_requires_vision'),
    ]

    operations = [
        migrations.CreateModel(
            name='ToolRateLimit',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('tool_name', models.CharField(help_text='Tool eligible for rate limiting. Use the tool name exactly as invoked by the agent.', max_length=128)),
                ('max_calls_per_hour', models.PositiveIntegerField(default=0, help_text='Maximum calls per agent in a sliding hour; set to 0 to disable enforcement.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('plan', models.ForeignKey(help_text='Tool configuration the rate limit applies to.', on_delete=django.db.models.deletion.CASCADE, related_name='rate_limits', to='api.toolconfig', to_field='plan_name')),
            ],
            options={
                'verbose_name': 'Tool rate limit',
                'verbose_name_plural': 'Tool rate limits',
                'ordering': ['plan', 'tool_name'],
            },
        ),
        migrations.AddConstraint(
            model_name='toolratelimit',
            constraint=models.UniqueConstraint(fields=('plan', 'tool_name'), name='unique_tool_rate_limit_per_plan_tool'),
        ),
        migrations.AddIndex(
            model_name='persistentagenttoolcall',
            index=models.Index(fields=['tool_name', 'step'], name='pa_tool_step_idx'),
        ),
    ]
