<?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('company_requests', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('신청자 ID');
            $table->string('business_number', 20)->comment('사업자등록번호');
            $table->string('company_name', 200)->comment('회사명');
            $table->string('ceo_name', 50)->nullable()->comment('대표자명');
            $table->string('address', 300)->nullable()->comment('주소');
            $table->string('phone', 30)->nullable()->comment('전화번호');
            $table->string('email', 100)->nullable()->comment('이메일');
            $table->string('status', 20)->default('pending')->comment('상태 (pending, approved, rejected)');
            $table->text('message')->nullable()->comment('신청 메시지');
            $table->text('reject_reason')->nullable()->comment('반려 사유');
            $table->json('barobill_response')->nullable()->comment('바로빌 검증 응답');
            $table->unsignedBigInteger('approved_by')->nullable()->comment('승인/반려 처리자');
            $table->unsignedBigInteger('created_tenant_id')->nullable()->comment('생성된 테넌트 ID');
            $table->timestamp('processed_at')->nullable()->comment('처리일시');
            $table->timestamps();

            $table->index('user_id', 'idx_company_requests_user_id');
            $table->index('business_number', 'idx_company_requests_business_number');
            $table->index('status', 'idx_company_requests_status');
        });
    }

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