<?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('account_codes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->onDelete('cascade');
            $table->string('code', 10)->comment('계정과목 코드');
            $table->string('name', 100)->comment('계정과목 명');
            $table->string('category', 50)->nullable()->comment('분류 (자산/부채/자본/수익/비용)');
            $table->integer('sort_order')->default(0)->comment('정렬순서');
            $table->boolean('is_active')->default(true)->comment('사용여부');
            $table->timestamps();

            // 테넌트별 계정과목 코드 유니크
            $table->unique(['tenant_id', 'code'], 'account_codes_tenant_code_unique');
            $table->index(['tenant_id', 'is_active'], 'account_codes_tenant_active_idx');
        });
    }

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