# Generated by Django 5.2.13 on 2026-04-16 21:18

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('appointments', '0001_initial'),
        ('finance', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='WhatsAppLog',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='fecha de creación')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='fecha de actualización')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='activo')),
                ('deleted_at', models.DateTimeField(blank=True, null=True, verbose_name='fecha de eliminación')),
                ('numero_telefono', models.CharField(max_length=20)),
                ('evento', models.CharField(choices=[('cita_confirmada', 'Cita Confirmada'), ('recordatorio_24h', 'Recordatorio 24h'), ('cita_cancelada', 'Cita Cancelada'), ('factura_disponible', 'Factura Disponible')], max_length=25)),
                ('estado', models.CharField(choices=[('enviado', 'Enviado'), ('error', 'Error'), ('reintentando', 'Reintentando'), ('descartado', 'Descartado')], default='reintentando', max_length=15)),
                ('mensaje_template', models.CharField(blank=True, default='', help_text='Nombre del template de Meta usado', max_length=100)),
                ('mensaje_params', models.JSONField(blank=True, default=dict, help_text='Parámetros enviados al template')),
                ('whatsapp_message_id', models.CharField(blank=True, default='', help_text='ID de mensaje retornado por la API de Meta', max_length=100)),
                ('intentos', models.PositiveSmallIntegerField(default=0)),
                ('error_detalle', models.TextField(blank=True, default='')),
                ('cita', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='whatsapp_logs', to='appointments.cita')),
                ('destinatario', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='whatsapp_logs', to=settings.AUTH_USER_MODEL)),
                ('factura', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='whatsapp_logs', to='finance.invoice')),
            ],
            options={
                'verbose_name': 'Log WhatsApp',
                'verbose_name_plural': 'Logs WhatsApp',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['evento', '-created_at'], name='notificatio_evento_f7a468_idx'), models.Index(fields=['estado', '-created_at'], name='notificatio_estado_a73b4a_idx'), models.Index(fields=['numero_telefono'], name='notificatio_numero__ca0cda_idx')],
            },
        ),
    ]
