<?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('approval_lines', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->onDelete('cascade')->comment('테넌트 ID');
            $table->string('name', 100)->comment('결재선 이름');
            $table->json('steps')->comment('결재선 단계 [{order, type: approval/agreement/reference, user_id, position}]');
            $table->boolean('is_default')->default(false)->comment('기본 결재선 여부');
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete()->comment('생성자');
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete()->comment('수정자');
            $table->foreignId('deleted_by')->nullable()->constrained('users')->nullOnDelete()->comment('삭제자');
            $table->softDeletes();
            $table->timestamps();

            $table->index('tenant_id', 'idx_tenant');
        });
    }

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