<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('servicios_diagnostico', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->enum('estado', ['pendiente', 'en_proceso', 'atendido', 'cancelado'])->default('pendiente');
            $table->text('notas')->nullable();
            
            // Documentos generados (booleanos)
            $table->boolean('pat_generado')->default(false);
            $table->boolean('ri_generado')->default(false);
            $table->boolean('otros_docs_generado')->default(false);
            
            // Compromiso completado trigger
            $table->integer('compromiso_completado')->default(1); // 1, 2 o 3
            
            $table->timestamp('fecha_inicio')->useCurrent();
            $table->timestamp('fecha_atencion')->nullable();
            $table->timestamps();
            
            // Índices para búsquedas rápidas
            $table->index('user_id');
            $table->index('estado');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('servicios_diagnostico');
    }
};
