<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('recepciones', function (Blueprint $table) {
            $table->id();
            $table->string('referencia_type');
            $table->unsignedBigInteger('referencia_id');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->integer('cantidad')->unsigned();
            $table->dateTime('fecha_recepcion')->nullable();
            $table->text('notas')->nullable();

            $table->timestamps();

            $table->index(['referencia_type', 'referencia_id']);
            $table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
        });
    }

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