# Generated by Django 6.0 on 2026-02-19 19:12

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0291_persistentagent_soft_delete_fields'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='AgentSpawnRequest',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('requested_charter', models.TextField(help_text='Requested charter for the spawned agent.')),
                ('handoff_message', models.TextField(help_text='Initial handoff message sent from parent to spawned agent.')),
                ('request_reason', models.TextField(blank=True, help_text='Optional explanation of why this spawn is needed.')),
                ('request_fingerprint', models.CharField(blank=True, editable=False, help_text='Deterministic fingerprint for deduplicating equivalent pending requests.', max_length=64)),
                ('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, null=True)),
            ],
            options={
                'ordering': ['-requested_at'],
            },
        ),
        migrations.AddField(
            model_name='agentspawnrequest',
            name='agent',
            field=models.ForeignKey(help_text='Source agent requesting a specialist peer.', on_delete=django.db.models.deletion.CASCADE, related_name='spawn_requests', to='api.persistentagent'),
        ),
        migrations.AddField(
            model_name='agentspawnrequest',
            name='peer_link',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spawn_requests', to='api.agentpeerlink'),
        ),
        migrations.AddField(
            model_name='agentspawnrequest',
            name='responded_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='agent_spawn_requests_responded', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='agentspawnrequest',
            name='spawned_agent',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spawned_from_requests', to='api.persistentagent'),
        ),
        migrations.AddIndex(
            model_name='agentspawnrequest',
            index=models.Index(fields=['agent', 'status'], name='spawn_req_agent_status_idx'),
        ),
        migrations.AddIndex(
            model_name='agentspawnrequest',
            index=models.Index(fields=['requested_at'], name='spawn_req_requested_idx'),
        ),
        migrations.AddConstraint(
            model_name='agentspawnrequest',
            constraint=models.UniqueConstraint(condition=models.Q(status='pending'), fields=('agent', 'request_fingerprint'), name='uniq_pending_agent_spawn_request'),
        ),
    ]
