<?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('production_orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('created_by')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete();
            $table->foreignId('factory_product_id')
                ->constrained('factory_products')
                ->restrictOnDelete();
            $table->foreignId('customer_order_item_id')
                ->nullable()
                ->constrained('customer_order_items')
                ->nullOnDelete();
            $table->decimal('quantity', 15, 3);
            $table->string('status', 32)->default('pending');
            $table->timestamp('completed_at')->nullable();
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

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