<?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('formularios', function (Blueprint $table) {
            $table->id();

            // Datos básicos (campos consultables)
            $table->string('identificador')->unique();
            $table->string('nombre_solicitante');
            $table->string('documento', 50)->index();
            $table->string('correo')->index();
            $table->string('telefono', 30)->nullable();

            // Disposiciones generales de contrato (claves consultables + JSON)
            $table->string('tipo_contrato')->index();     // p. ej. CPS, Orden, Etc.
            $table->date('vigencia_inicio')->nullable()->index();
            $table->date('vigencia_fin')->nullable()->index();
            $table->json('disposiciones')->nullable();

            // Ejecución
            $table->string('responsable')->nullable()->index();
            $table->date('fecha_inicio_ejecucion')->nullable()->index();
            $table->date('fecha_fin_ejecucion')->nullable()->index();
            $table->json('ejecucion')->nullable();

            // Indicadores / Resultados
            $table->unsignedInteger('kpi_entregables')->default(0);
            $table->unsignedInteger('kpi_cumplimiento')->default(0);
            $table->json('indicadores')->nullable();

            $table->timestamps();
        });
    }

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