<?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('variant_stock_movements', function (Blueprint $table) {
            $table->id();
            $table->foreignId('variant_id')->constrained('product_variants')->onDelete('cascade');
            $table->integer('change'); // positive for additions, negative for deductions
            $table->string('reason'); // 'order', 'restock', 'adjustment', 'return', etc.
            $table->unsignedBigInteger('reference_id')->nullable(); // order_id, adjustment_id, etc.
            $table->unsignedBigInteger('created_by')->nullable(); // user_id
            $table->timestamps();

            $table->index('variant_id');
            $table->index('reference_id');
            $table->index('created_by');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('variant_stock_movements');
    }
};
