# Generated by Django 5.2 on 2025-08-26 23:39

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0100_add_agent_allowlist_invite'),
    ]

    operations = [
        migrations.AlterField(
            model_name='persistentagentsystemstep',
            name='code',
            field=models.CharField(choices=[('PROCESS_EVENTS', 'Process Events'), ('SNAPSHOT', 'Snapshot'), ('CREDENTIALS_PROVIDED', 'Credentials Provided'), ('CONTACTS_APPROVED', 'Contacts Approved')], max_length=64),
        ),
        migrations.CreateModel(
            name='CommsAllowlistRequest',
            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)),
                ('name', models.CharField(blank=True, help_text="Contact's name if known", max_length=256)),
                ('reason', models.TextField(help_text='Why the agent needs to contact this person')),
                ('purpose', models.CharField(help_text="Brief purpose of communication (e.g., 'Schedule meeting', 'Get approval')", max_length=512)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('expired', 'Expired')], default='pending', max_length=16)),
                ('requested_at', models.DateTimeField(auto_now_add=True)),
                ('responded_at', models.DateTimeField(blank=True, null=True)),
                ('expires_at', models.DateTimeField(blank=True, help_text='Optional expiry for this request', null=True)),
                ('agent', models.ForeignKey(help_text='Agent requesting contact permission', on_delete=django.db.models.deletion.CASCADE, related_name='contact_requests', to='api.persistentagent')),
                ('allowlist_entry', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='from_request', to='api.commsallowlistentry')),
            ],
            options={
                'ordering': ['-requested_at'],
                'indexes': [models.Index(fields=['agent', 'status'], name='contact_req_agent_status_idx'), models.Index(fields=['requested_at'], name='contact_req_requested_idx')],
                'constraints': [models.UniqueConstraint(condition=models.Q(('status', 'pending')), fields=('agent', 'channel', 'address'), name='uniq_pending_contact_request')],
            },
        ),
    ]
