# Generated by Django 5.2 on 2025-06-30 01:47

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0051_persistentagent_owner'),
    ]

    operations = [
        migrations.CreateModel(
            name='OutboundMessageAttempt',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('provider', models.CharField(max_length=32)),
                ('provider_message_id', models.CharField(blank=True, db_index=True, max_length=128)),
                ('status', models.CharField(choices=[('queued', 'Queued'), ('sending', 'Sending'), ('sent', 'Sent to provider'), ('delivered', 'Delivered'), ('failed', 'Failed')], db_index=True, max_length=16)),
                ('queued_at', models.DateTimeField(auto_now_add=True)),
                ('sent_at', models.DateTimeField(blank=True, null=True)),
                ('delivered_at', models.DateTimeField(blank=True, null=True)),
                ('error_code', models.CharField(blank=True, max_length=64)),
                ('error_message', models.TextField(blank=True)),
            ],
            options={
                'ordering': ['-queued_at'],
            },
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='latest_delivered_at',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='latest_error_code',
            field=models.CharField(blank=True, max_length=64),
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='latest_error_message',
            field=models.CharField(blank=True, max_length=256),
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='latest_sent_at',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='persistentagentmessage',
            name='latest_status',
            field=models.CharField(choices=[('queued', 'Queued'), ('sending', 'Sending'), ('sent', 'Sent to provider'), ('delivered', 'Delivered'), ('failed', 'Failed')], db_index=True, default='queued', max_length=16),
        ),
        migrations.AlterField(
            model_name='persistentagent',
            name='schedule',
            field=models.CharField(blank=True, help_text="Cron-like schedule expression or interval (e.g., '@daily', '@every 30m').", max_length=128, null=True),
        ),
        migrations.AddIndex(
            model_name='persistentagentmessage',
            index=models.Index(fields=['latest_status'], name='pa_msg_latest_status_idx'),
        ),
        migrations.AddField(
            model_name='outboundmessageattempt',
            name='message',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attempts', to='api.persistentagentmessage'),
        ),
        migrations.AddIndex(
            model_name='outboundmessageattempt',
            index=models.Index(fields=['status', '-queued_at'], name='msg_attempt_status_idx'),
        ),
        migrations.AddIndex(
            model_name='outboundmessageattempt',
            index=models.Index(fields=['provider_message_id'], name='msg_attempt_provider_id_idx'),
        ),
        migrations.AddIndex(
            model_name='outboundmessageattempt',
            index=models.Index(fields=['provider'], name='msg_attempt_provider_idx'),
        ),
    ]
