<?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_templates', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('equipment_id')->comment('설비 ID');
            $table->integer('item_no')->comment('항목번호 (1,2,3,4)');
            $table->string('check_point', 50)->comment('점검개소 (겉모양, 스위치, 롤러 등)');
            $table->string('check_item', 100)->comment('점검항목 (청결상태, 작동상태 등)');
            $table->string('check_timing', 20)->nullable()->comment('시기: operating/stopped');
            $table->string('check_frequency', 50)->nullable()->comment('주기 (1회/일)');
            $table->text('check_method')->nullable()->comment('점검방법 및 기준');
            $table->integer('sort_order')->default(0)->comment('정렬순서');
            $table->tinyInteger('is_active')->default(1)->comment('사용여부');
            $table->timestamps();

            $table->unique(['equipment_id', 'item_no'], 'uq_equipment_item_no');
            $table->index('tenant_id', 'idx_insp_tmpl_tenant');

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

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