<?php

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

return new class extends Migration
{
    /**
     * PRC-72 — premium domain support infrastructure. Three columns added
     * nullable + default false; backwards-compatible with all existing
     * registrar modules (none touch these fields yet — that's V2).
     */
    public function up(): void
    {
        Schema::table('client_domains', function (Blueprint $table) {
            // is_premium kolonu önceki bir migration'da eklenmiş; sadece premium fiyat
            // kolonlarını ekle.
            if (! Schema::hasColumn('client_domains', 'premium_purchase_amount')) {
                $table->decimal('premium_purchase_amount', 10, 2)->nullable()->after('is_premium');
            }
            if (! Schema::hasColumn('client_domains', 'premium_renewal_amount')) {
                $table->decimal('premium_renewal_amount', 10, 2)->nullable()->after('premium_purchase_amount');
            }
        });
    }

    public function down(): void
    {
        Schema::table('client_domains', function (Blueprint $table) {
            $cols = [];
            if (Schema::hasColumn('client_domains', 'premium_purchase_amount')) {
                $cols[] = 'premium_purchase_amount';
            }
            if (Schema::hasColumn('client_domains', 'premium_renewal_amount')) {
                $cols[] = 'premium_renewal_amount';
            }
            if (! empty($cols)) {
                $table->dropColumn($cols);
            }
        });
    }
};
