<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Core\Enums\StatusEnum;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('stocks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('inventory_department_id')->constrained()->cascadeOnDelete();
            $table->foreignId('product_id')->constrained()->cascadeOnDelete();
            $table->decimal('current_qty', 20, 6)->default(0)->comment('ALWAYS Stored In Product Base Unit');
            $table->decimal('reserved_qty', 20, 6)->default(0);
            $table->decimal('damaged_qty', 20, 6)->default(0);
            $table->enum('status', StatusEnum::casesAsArray())->index()->default(StatusEnum::ACTIVE);

            $table->timestamps();
            $table->softDeletes();

            $table->unique(['inventory_department_id', 'product_id']);
        });
    }

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