<?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('indirect_goods_request_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('indirect_goods_request_id')
                  ->constrained('indirect_goods_requests')->onDelete('cascade');
            $table->foreignId('indirect_good_id')
                  ->constrained('indirect_goods')->onDelete('cascade');
            $table->string('invoice_number', 100)->nullable();
            $table->decimal('quantity_requested', 10, 2);
            $table->decimal('quantity_released', 10, 2)->default(0);
            $table->decimal('quantity_balance', 10, 2)->default(0);
            $table->decimal('unit_price', 10, 2)->default(0);
            $table->decimal('total_price', 15, 2)->default(0);
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index('indirect_good_id');
        });
    }

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