# Generated by Django 5.2 on 2025-10-09 18:17

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0155_agenttransferinvite'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='DedicatedProxyAllocation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('notes', models.TextField(blank=True)),
                ('allocated_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['-allocated_at'],
            },
        ),
        migrations.AddField(
            model_name='proxyserver',
            name='is_dedicated',
            field=models.BooleanField(default=False, help_text='Marked true when this proxy is held as dedicated inventory and not part of the shared pool.'),
        ),
        migrations.AddIndex(
            model_name='proxyserver',
            index=models.Index(fields=['is_dedicated'], name='api_proxyse_is_dedi_cd7282_idx'),
        ),
        migrations.AddField(
            model_name='dedicatedproxyallocation',
            name='owner_organization',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dedicated_proxy_allocations', to='api.organization'),
        ),
        migrations.AddField(
            model_name='dedicatedproxyallocation',
            name='owner_user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dedicated_proxy_allocations', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='dedicatedproxyallocation',
            name='proxy',
            field=models.OneToOneField(help_text='Proxy reserved for this owner.', on_delete=django.db.models.deletion.CASCADE, related_name='dedicated_allocation', to='api.proxyserver'),
        ),
        migrations.AddIndex(
            model_name='dedicatedproxyallocation',
            index=models.Index(fields=['owner_user'], name='api_dedicat_owner_u_611636_idx'),
        ),
        migrations.AddIndex(
            model_name='dedicatedproxyallocation',
            index=models.Index(fields=['owner_organization'], name='api_dedicat_owner_o_c959e8_idx'),
        ),
        migrations.AddConstraint(
            model_name='dedicatedproxyallocation',
            constraint=models.CheckConstraint(condition=models.Q(models.Q(('owner_user__isnull', False), ('owner_organization__isnull', True)), models.Q(('owner_user__isnull', True), ('owner_organization__isnull', False)), _connector='OR'), name='dedicated_proxy_single_owner'),
        ),
    ]
