<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('item_pages', function (Blueprint $table) {
            $table->id()->comment('품목 페이지 ID');
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('page_name')->comment('페이지명');
            $table->enum('item_type', ['FG', 'PT', 'SM', 'RM', 'CS'])->comment('품목 유형 (FG: 완제품, PT: 반제품, SM: 부자재, RM: 원자재, CS: 소모품)');
            $table->string('absolute_path', 500)->nullable()->comment('절대 경로');
            $table->boolean('is_active')->default(true)->comment('활성 여부');
            $table->unsignedBigInteger('created_by')->nullable()->comment('생성자 ID');
            $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자 ID');
            $table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자 ID');
            $table->timestamps();
            $table->softDeletes()->comment('소프트 삭제');

            // 인덱스
            $table->index('tenant_id', 'idx_item_pages_tenant_id');
            $table->index('item_type', 'idx_item_pages_item_type');

            // 외래키
            $table->foreign('tenant_id', 'fk_item_pages_tenant')
                ->references('id')->on('tenants')
                ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('item_pages');
    }
};
