# Generated by Django 5.2 on 2025-08-26 16:33

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0099_add_cc_endpoints_to_message'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='AgentAllowlistInvite',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('channel', models.CharField(choices=[('email', 'Email'), ('sms', 'SMS'), ('slack', 'Slack'), ('discord', 'Discord'), ('other', 'Other')], max_length=32)),
                ('address', models.CharField(help_text='Email address or E.164 phone number', max_length=512)),
                ('token', models.CharField(help_text='Unique token for accept/reject URLs', max_length=64, unique=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('accepted', 'Accepted'), ('rejected', 'Rejected'), ('expired', 'Expired')], default='pending', max_length=16)),
                ('expires_at', models.DateTimeField(help_text='When this invitation expires')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('responded_at', models.DateTimeField(blank=True, help_text='When they accepted/rejected', null=True)),
                ('agent', models.ForeignKey(help_text='Agent this invitation is for', on_delete=django.db.models.deletion.CASCADE, related_name='allowlist_invites', to='api.persistentagent')),
                ('invited_by', models.ForeignKey(help_text='User who sent this invitation', on_delete=django.db.models.deletion.CASCADE, related_name='sent_allowlist_invites', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['token'], name='allow_invite_token_idx'), models.Index(fields=['agent', 'status'], name='allow_invite_agent_status_idx')],
                'constraints': [models.UniqueConstraint(condition=models.Q(('status__in', ['pending', 'accepted'])), fields=('agent', 'channel', 'address'), name='uniq_active_allowlist_invite')],
            },
        ),
    ]
