<?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('reportes', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('pago_id')->nullable();
            $table->string('nombre'); // Ej: "Gestión Estratégica"
            $table->string('tipo'); // Ej: "compromiso1", "evaluaciones", etc
            $table->string('ruta_archivo'); // Ruta al archivo generado
            $table->string('estado')->default('generado'); // generado, descargado, etc
            $table->timestamp('fecha_generacion')->useCurrent();
            $table->integer('descargas')->default(0);
            $table->timestamps();
            
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('pago_id')->references('id')->on('pagos')->onDelete('set null');
        });
    }

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