<?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('equipment_process', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('equipment_id')->comment('설비 ID');
            $table->unsignedBigInteger('process_id')->comment('공정 ID');
            $table->tinyInteger('is_primary')->default(0)->comment('주 설비 여부');
            $table->timestamps();

            $table->unique(['equipment_id', 'process_id'], 'uq_equipment_process');

            $table->foreign('equipment_id')
                ->references('id')
                ->on('equipments')
                ->onDelete('cascade');

            $table->foreign('process_id')
                ->references('id')
                ->on('processes')
                ->onDelete('cascade');
        });
    }

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