<?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('custom_tabs', function (Blueprint $table) {
            $table->id()->comment('커스텀 탭 ID');
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('label')->comment('탭 라벨');
            $table->string('icon', 100)->nullable()->comment('아이콘');
            $table->boolean('is_default')->default(false)->comment('기본 탭 여부');
            $table->integer('order_no')->default(0)->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_custom_tabs_tenant_id');
            $table->index(['tenant_id', 'order_no'], 'idx_custom_tabs_order');

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

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