<?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('manufacturing_run_pieces', function (Blueprint $table) {
            $table->id();
            $table->foreignId('manufacturing_run_id')->constrained('manufacturing_runs')->onDelete('cascade');
            $table->integer('piece_number')->comment('Piece number (can be any integer: 1, 5, 10, 100, etc.)');
            $table->decimal('length', 15, 4)->comment('Actual length of the piece in base unit');
            $table->enum('status', ['complete', 'partial', 'b_grade'])->default('complete')->comment('Piece status');
            $table->text('notes')->nullable()->comment('Additional notes about the piece');
            $table->timestamps();

            // Indexes
            $table->index(['manufacturing_run_id', 'piece_number']);
            $table->index(['manufacturing_run_id', 'status']);
        });
    }

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