# Generated by Django 5.2 on 2025-11-25 20:40

import django.core.validators
import django.db.models.deletion
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0205_merge_20251125_1840'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ProfilePersistentTier',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('order', models.PositiveIntegerField(help_text='1-based order within the range')),
                ('description', models.CharField(blank=True, max_length=256)),
                ('is_premium', models.BooleanField(db_index=True, default=False, help_text='Marks tiers reserved for premium routing.')),
                ('is_max', models.BooleanField(db_index=True, default=False, help_text='Marks tiers reserved for max-tier routing.')),
                ('credit_multiplier', models.DecimalField(decimal_places=2, default=Decimal('1.00'), help_text='Multiplier applied to credit consumption for this tier.', max_digits=6, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))])),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['token_range__profile', 'token_range__min_tokens', 'order'],
            },
        ),
        migrations.AddField(
            model_name='evalrun',
            name='llm_routing_profile_name',
            field=models.CharField(blank=True, help_text='Snapshot of profile name at run time (preserved if profile deleted).', max_length=64),
        ),
        migrations.CreateModel(
            name='LLMRoutingProfile',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.SlugField(help_text="URL-safe identifier, e.g., 'production-v3', 'eval-gpt5-only'", max_length=64, unique=True)),
                ('display_name', models.CharField(max_length=128)),
                ('description', models.TextField(blank=True)),
                ('is_active', models.BooleanField(db_index=True, default=False, help_text='Active profile used for all runtime routing. Only one can be active.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('cloned_from', models.ForeignKey(blank=True, help_text='Source profile this was cloned from, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='clones', to='api.llmroutingprofile')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_llm_profiles', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-is_active', 'display_name'],
            },
        ),
        migrations.AddField(
            model_name='evalrun',
            name='llm_routing_profile',
            field=models.ForeignKey(blank=True, help_text='LLM routing profile used for this run.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='eval_runs', to='api.llmroutingprofile'),
        ),
        migrations.AddField(
            model_name='evalsuiterun',
            name='llm_routing_profile',
            field=models.ForeignKey(blank=True, help_text='LLM routing profile to use for this suite. If null, uses active profile.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='eval_suite_runs', to='api.llmroutingprofile'),
        ),
        migrations.CreateModel(
            name='ProfileBrowserTier',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('order', models.PositiveIntegerField(help_text='1-based order within the profile')),
                ('description', models.CharField(blank=True, max_length=256)),
                ('is_premium', models.BooleanField(db_index=True, default=False, help_text='Marks tiers reserved for premium browser routing.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='browser_tiers', to='api.llmroutingprofile')),
            ],
            options={
                'ordering': ['profile', 'order'],
            },
        ),
        migrations.CreateModel(
            name='ProfileBrowserTierEndpoint',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('weight', models.FloatField(help_text='Relative weight within the tier; must be > 0.')),
                ('is_premium', models.BooleanField(db_index=True, default=False, editable=False, help_text='Matches the premium status of the associated tier.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('endpoint', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='in_profile_tiers', to='api.browsermodelendpoint')),
                ('tier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tier_endpoints', to='api.profilebrowsertier')),
            ],
            options={
                'ordering': ['tier__order', 'endpoint__key'],
            },
        ),
        migrations.CreateModel(
            name='ProfileEmbeddingsTier',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('order', models.PositiveIntegerField(help_text='1-based order within the profile')),
                ('description', models.CharField(blank=True, max_length=256)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='embeddings_tiers', to='api.llmroutingprofile')),
            ],
            options={
                'ordering': ['profile', 'order'],
            },
        ),
        migrations.CreateModel(
            name='ProfileEmbeddingsTierEndpoint',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('weight', models.FloatField(help_text='Relative weight within the tier; must be > 0.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('endpoint', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='in_profile_tiers', to='api.embeddingsmodelendpoint')),
                ('tier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tier_endpoints', to='api.profileembeddingstier')),
            ],
            options={
                'ordering': ['tier__order', 'endpoint__key'],
            },
        ),
        migrations.CreateModel(
            name='ProfilePersistentTierEndpoint',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('weight', models.FloatField(help_text='Relative weight within the tier; must be > 0.')),
                ('is_premium', models.BooleanField(db_index=True, default=False, editable=False, help_text='Matches the premium status of the associated tier.')),
                ('is_max', models.BooleanField(db_index=True, default=False, editable=False, help_text='Matches the max-tier status of the associated tier.')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('endpoint', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='in_profile_tiers', to='api.persistentmodelendpoint')),
                ('tier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tier_endpoints', to='api.profilepersistenttier')),
            ],
            options={
                'ordering': ['tier__order', 'endpoint__key'],
            },
        ),
        migrations.CreateModel(
            name='ProfileTokenRange',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(help_text="Range name, e.g., 'small', 'medium', 'large'", max_length=64)),
                ('min_tokens', models.PositiveIntegerField()),
                ('max_tokens', models.PositiveIntegerField(blank=True, help_text='Exclusive upper bound; null means infinity', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='persistent_token_ranges', to='api.llmroutingprofile')),
            ],
            options={
                'ordering': ['profile', 'min_tokens'],
            },
        ),
        migrations.AddField(
            model_name='profilepersistenttier',
            name='token_range',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tiers', to='api.profiletokenrange'),
        ),
        migrations.AddIndex(
            model_name='llmroutingprofile',
            index=models.Index(fields=['name'], name='api_llmrout_name_1adea0_idx'),
        ),
        migrations.AddIndex(
            model_name='llmroutingprofile',
            index=models.Index(fields=['is_active'], name='api_llmrout_is_acti_e948a9_idx'),
        ),
        migrations.AddConstraint(
            model_name='llmroutingprofile',
            constraint=models.UniqueConstraint(condition=models.Q(('is_active', True)), fields=('is_active',), name='unique_active_llm_routing_profile'),
        ),
        migrations.AlterUniqueTogether(
            name='profilebrowsertier',
            unique_together={('profile', 'order', 'is_premium')},
        ),
        migrations.AlterUniqueTogether(
            name='profilebrowsertierendpoint',
            unique_together={('tier', 'endpoint')},
        ),
        migrations.AlterUniqueTogether(
            name='profileembeddingstier',
            unique_together={('profile', 'order')},
        ),
        migrations.AlterUniqueTogether(
            name='profileembeddingstierendpoint',
            unique_together={('tier', 'endpoint')},
        ),
        migrations.AlterUniqueTogether(
            name='profilepersistenttierendpoint',
            unique_together={('tier', 'endpoint')},
        ),
        migrations.AddIndex(
            model_name='profiletokenrange',
            index=models.Index(fields=['profile', 'min_tokens', 'max_tokens'], name='api_profile_profile_2af4f3_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='profiletokenrange',
            unique_together={('profile', 'name')},
        ),
        migrations.AddConstraint(
            model_name='profilepersistenttier',
            constraint=models.CheckConstraint(condition=models.Q(('is_max', True), ('is_premium', True), _negated=True), name='profilepersistenttier_max_excludes_premium'),
        ),
        migrations.AlterUniqueTogether(
            name='profilepersistenttier',
            unique_together={('token_range', 'order', 'is_premium', 'is_max')},
        ),
    ]
