<?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('structure_reviews', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->comment('테넌트 ID');
            $table->string('review_number', 50)->nullable()->comment('검토번호');
            $table->foreignId('partner_id')->nullable()->comment('거래처 ID');
            $table->string('partner_name', 100)->nullable()->comment('거래처명');
            $table->foreignId('site_id')->nullable()->comment('현장 ID');
            $table->string('site_name', 200)->nullable()->comment('현장명');
            $table->date('request_date')->nullable()->comment('구조검토 의뢰일');
            $table->string('review_company', 100)->nullable()->comment('구조검토 회사');
            $table->string('reviewer_name', 50)->nullable()->comment('구조검토자');
            $table->date('review_date')->nullable()->comment('구조검토일');
            $table->date('completion_date')->nullable()->comment('구조검토 완료일');
            $table->string('status', 20)->default('pending')->comment('상태: pending, completed');
            $table->string('file_url', 500)->nullable()->comment('구조검토 파일 URL');
            $table->text('remarks')->nullable()->comment('비고');
            $table->boolean('is_active')->default(true)->comment('활성화 여부');
            $table->foreignId('created_by')->nullable()->comment('생성자 ID');
            $table->foreignId('updated_by')->nullable()->comment('수정자 ID');
            $table->foreignId('deleted_by')->nullable()->comment('삭제자 ID');
            $table->timestamps();
            $table->softDeletes();

            // 인덱스
            $table->index('tenant_id');
            $table->index('partner_id');
            $table->index('site_id');
            $table->index('status');
            $table->index('request_date');
            $table->index('created_at');
        });
    }

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