<?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_inspection_details', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('inspection_id')->comment('점검 헤더 ID');
            $table->unsignedBigInteger('template_item_id')->comment('점검항목 템플릿 ID');
            $table->date('check_date')->comment('점검일');
            $table->string('result', 10)->nullable()->comment('결과: good/bad/repaired');
            $table->string('note', 500)->nullable()->comment('비고');
            $table->timestamps();

            $table->unique(['inspection_id', 'template_item_id', 'check_date'], 'uq_inspection_detail');

            $table->foreign('inspection_id')
                ->references('id')
                ->on('equipment_inspections')
                ->onDelete('cascade');

            $table->foreign('template_item_id')
                ->references('id')
                ->on('equipment_inspection_templates')
                ->onDelete('cascade');
        });
    }

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