<?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('solicitud_bienes', function (Blueprint $table): void {
            $table->id();
            $table->string('numero_solicitud', 40)->unique();
            $table->string('solicitante_cedula', 20)->index();
            $table->string('estado', 40)->default('pendiente')->index();
            $table->unsignedInteger('articulos_count')->default(0);
            $table->unsignedInteger('unidades_count')->default(0);
            $table->json('detalle_json');
            $table->text('observaciones')->nullable();
            $table->timestamp('fecha_solicitud')->useCurrent()->index();
            $table->timestamps();

            $table->foreign('solicitante_cedula')
                ->references('cedula')
                ->on('users')
                ->onUpdate('cascade');
        });
    }

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