<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * clients 테이블에서 bad_debt 관련 컬럼 제거
 *
 * 악성채권 정보는 이제 bad_debts 테이블에서 관리됨
 * clients.bad_debts() 관계를 통해 조회
 */
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('clients', function (Blueprint $table) {
            $table->dropColumn([
                'bad_debt',
                'bad_debt_amount',
                'bad_debt_receive_date',
                'bad_debt_end_date',
                'bad_debt_progress',
            ]);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('clients', function (Blueprint $table) {
            $table->boolean('bad_debt')->default(false)->after('tax_end_date')->comment('악성채권 여부');
            $table->decimal('bad_debt_amount', 15, 2)->nullable()->after('bad_debt')->comment('악성채권 금액');
            $table->date('bad_debt_receive_date')->nullable()->after('bad_debt_amount')->comment('악성채권 발생일');
            $table->date('bad_debt_end_date')->nullable()->after('bad_debt_receive_date')->comment('악성채권 종료일');
            $table->string('bad_debt_progress', 20)->nullable()->after('bad_debt_end_date')->comment('악성채권 진행상황');
        });
    }
};
