<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * 작업지시 벤딩 상세 테이블 (Bending Process Details)
     */
    public function up(): void
    {
        Schema::create('work_order_bending_details', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('work_order_id')->comment('작업지시ID');

            // 벤딩 공정 세부 항목
            $table->boolean('shaft_cutting')->default(false)->comment('샤프트 절단');
            $table->boolean('bearing')->default(false)->comment('베어링');
            $table->boolean('shaft_welding')->default(false)->comment('샤프트 용접');
            $table->boolean('assembly')->default(false)->comment('조립');
            $table->boolean('winder_welding')->default(false)->comment('와인더 용접');
            $table->boolean('frame_assembly')->default(false)->comment('프레임 조립');
            $table->boolean('bundle_assembly')->default(false)->comment('번들 조립');
            $table->boolean('motor_assembly')->default(false)->comment('모터 조립');
            $table->boolean('bracket_assembly')->default(false)->comment('브라켓 조립');

            $table->timestamps();

            // Foreign Keys
            $table->foreign('work_order_id')
                ->references('id')
                ->on('work_orders')
                ->onDelete('cascade');

            // Unique (1:1 관계)
            $table->unique('work_order_id', 'uq_bending_details_work_order');
        });
    }

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