<?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('unit_options', function (Blueprint $table) {
            $table->id()->comment('단위 옵션 ID');
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('label', 100)->comment('단위 라벨');
            $table->string('value', 50)->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_unit_options_tenant_id');

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

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