<?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('stock_mutations', function (Blueprint $table) {
            $table->id();
            $table->morphs('stockable');
            $table->string('type');
            $table->nullableMorphs('source');
            $table->decimal('quantity', 18, 4);
            $table->decimal('stock_before', 18, 4);
            $table->decimal('stock_after', 18, 4);
            $table->string('stock_quality')->nullable();
            $table->string('description')->nullable();
            $table->foreignId('user_id')->constrained();
            $table->timestamps();

            $table->index(['stockable_type', 'stockable_id', 'created_at']);
        });
    }

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