<?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('stock_movements', function (Blueprint $table) {
            $table->id();
            $table->foreignId('fibre_type_id')->constrained()->onDelete('cascade');
            $table->enum('type', ['in', 'out']); // 'in' for stock addition, 'out' for stock reduction
            $table->decimal('quantity', 10, 2); // Quantity moved (always positive)
            $table->decimal('quantity_before', 10, 2); // Stock quantity before the movement
            $table->decimal('quantity_after', 10, 2); // Stock quantity after the movement
            $table->string('reason'); // Reason for the movement (e.g., 'Initial stock', 'Order #123', 'Stock adjustment')
            $table->string('reference_type')->nullable(); // Type of reference (e.g., 'order', 'stock_adjustment')
            $table->unsignedBigInteger('reference_id')->nullable(); // ID of the reference record
            $table->text('notes')->nullable(); // Additional notes
            $table->timestamps();
        });
    }

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