<?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('labors', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('labor_number', 50)->comment('노임번호');
            $table->enum('category', ['가로', '세로할증'])->comment('구분');
            $table->decimal('min_m', 10, 2)->default(0)->comment('최소 m');
            $table->decimal('max_m', 10, 2)->default(0)->comment('최대 m');
            $table->unsignedInteger('labor_price')->nullable()->comment('노임단가');
            $table->enum('status', ['사용', '중지'])->default('사용')->comment('상태');
            $table->boolean('is_active')->default(true)->comment('활성화 여부 (ModelTrait::scopeActive() 사용)');
            $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();

            // 인덱스
            $table->index(['tenant_id', 'category'], 'idx_tenant_category');
            $table->index(['tenant_id', 'status'], 'idx_tenant_status');
            $table->index(['tenant_id', 'labor_number'], 'idx_tenant_labor_number');
        });
    }

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