<?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('work_order_materials', function (Blueprint $table) {
            $table->id();
            $table->foreignId('work_order_id')->constrained()->cascadeOnDelete();
            $table->foreignId('item_id')->constrained()->restrictOnDelete();
            $table->decimal('required_quantity', 20, 6);
            $table->decimal('issued_quantity', 20, 6)->default(0);
            $table->decimal('consumed_quantity', 20, 6)->default(0);
            $table->decimal('scrap_quantity', 20, 6)->default(0);
            $table->timestamps();
            $table->index(['work_order_id', 'item_id']);

        });
    }

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