<?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('handover_report_managers', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('handover_report_id')->comment('인수인계보고서 ID');

            // 담당자 정보
            $table->string('name')->comment('담당자명');
            $table->text('non_performance_reason')->nullable()->comment('미이행 사유');
            $table->text('signature')->nullable()->comment('서명 (Base64 또는 URL)');

            // 순서
            $table->integer('sort_order')->default(0)->comment('정렬 순서');

            // 감사 컬럼
            $table->unsignedBigInteger('created_by')->nullable()->comment('생성자 ID');
            $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자 ID');

            // 타임스탬프
            $table->timestamps();

            // 인덱스
            $table->index('tenant_id');
            $table->index('handover_report_id');

            // 외래키
            $table->foreign('handover_report_id')
                ->references('id')
                ->on('handover_reports')
                ->onDelete('cascade');
        });
    }

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