<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('notificaciones', function (Blueprint $table) {
            $table->id();
            $table->foreignId('caso_id')->constrained()->onDelete('cascade');
            $table->string('tipo');
            $table->string('destinatario');
            $table->string('email')->nullable();
            $table->string('telefono')->nullable();
            $table->text('mensaje');
            $table->enum('canal', ['email', 'whatsapp', 'sms', 'todos'])->default('todos');
            $table->enum('estado', ['pendiente', 'enviada', 'entregada', 'fallida'])->default('pendiente');
            $table->timestamp('fecha_envio')->nullable();
            $table->text('respuesta')->nullable();
            $table->timestamps();

            $table->index('estado');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('notificaciones');
    }
};
