<?php

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

return new class extends Migration
{
    /**
     * 영업관리 테이블에 입금 정보 컬럼 추가
     */
    public function up(): void
    {
        Schema::table('sales_tenant_managements', function (Blueprint $table) {
            // 계약금 정보
            $table->decimal('deposit_amount', 14, 2)->nullable()->after('membership_status')->comment('계약금');
            $table->date('deposit_paid_date')->nullable()->after('deposit_amount')->comment('계약금 입금일');
            $table->enum('deposit_status', ['pending', 'paid'])
                ->default('pending')
                ->after('deposit_paid_date')
                ->comment('계약금 상태 (pending:대기, paid:입금완료)');

            // 잔금 정보
            $table->decimal('balance_amount', 14, 2)->nullable()->after('deposit_status')->comment('잔금');
            $table->date('balance_paid_date')->nullable()->after('balance_amount')->comment('잔금 입금일');
            $table->enum('balance_status', ['pending', 'paid'])
                ->default('pending')
                ->after('balance_paid_date')
                ->comment('잔금 상태 (pending:대기, paid:입금완료)');

            // 총 가입비 (계약 상품 합계, 캐시용)
            $table->decimal('total_registration_fee', 14, 2)->nullable()->after('balance_status')->comment('총 가입비');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('sales_tenant_managements', function (Blueprint $table) {
            $table->dropColumn([
                'deposit_amount',
                'deposit_paid_date',
                'deposit_status',
                'balance_amount',
                'balance_paid_date',
                'balance_status',
                'total_registration_fee',
            ]);
        });
    }
};
