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

            // ITEM 정보
            $table->integer('item_no')->default(0)->comment('순번');
            $table->string('name')->comment('명칭');
            $table->string('product')->nullable()->comment('제품');
            $table->integer('quantity')->default(0)->comment('수량');
            $table->text('remark')->nullable()->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->index(['handover_report_id', 'item_no']);

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

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