<?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
    {
        if (Schema::hasTable('product_installment_plans') && !Schema::hasColumn('product_installment_plans', 'installment_amounts')) {
            Schema::table('product_installment_plans', function (Blueprint $table) {
                // Nullable JSON array of piaster amounts per slot index; null slot = auto-calculate
                $table->jsonb('installment_amounts')->nullable()->after('down_payment_pct');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('product_installment_plans', 'installment_amounts')) {
            Schema::table('product_installment_plans', function (Blueprint $table) {
                $table->dropColumn('installment_amounts');
            });
        }
    }
};
