<?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::table('credit_inquiries', function (Blueprint $table) {
            // 기업 기본정보 (OA08)
            $table->string('ceo_name')->nullable()->after('company_name')->comment('대표자명');
            $table->string('company_address')->nullable()->after('ceo_name')->comment('회사 주소');
            $table->string('business_type')->nullable()->after('company_address')->comment('업종');
            $table->string('business_item')->nullable()->after('business_type')->comment('업태');
            $table->date('establishment_date')->nullable()->after('business_item')->comment('설립일');

            // 국세청 사업자등록 상태
            $table->string('nts_status', 20)->nullable()->after('establishment_date')->comment('국세청 상태 (영업/휴업/폐업)');
            $table->string('nts_status_code', 2)->nullable()->after('nts_status')->comment('국세청 상태코드 (01/02/03)');
            $table->string('nts_tax_type', 50)->nullable()->after('nts_status_code')->comment('과세유형');
            $table->date('nts_closure_date')->nullable()->after('nts_tax_type')->comment('폐업일');

            // API 원본 데이터
            $table->json('raw_company_info')->nullable()->after('raw_workout_info')->comment('OA08 기업기본정보 원본');
            $table->json('raw_nts_status')->nullable()->after('raw_company_info')->comment('국세청 상태조회 원본');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('credit_inquiries', function (Blueprint $table) {
            $table->dropColumn([
                'ceo_name',
                'company_address',
                'business_type',
                'business_item',
                'establishment_date',
                'nts_status',
                'nts_status_code',
                'nts_tax_type',
                'nts_closure_date',
                'raw_company_info',
                'raw_nts_status',
            ]);
        });
    }
};
