<?php

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

return new class extends Migration
{
    /**
     * Run the migrations - Rollback to original reseller_plans structure.
     */
    public function up(): void
    {
        Schema::table('reseller_plans', function (Blueprint $table) {
            // Drop new columns added in 2025_11_22_182804
            $table->dropColumn([
                'max_dns_zones',
                'max_subdomains',
                'allocated_nameservers',
                'allow_import_export',
                'allow_api_access',
                'allow_dyndns',
                'dyndns_limit'
            ]);

            // Restore original columns
            $table->integer('dns_zones_per_client')->default(10)->after('max_clients');
            $table->integer('subdomains_per_client')->default(50)->after('dns_zones_per_client');
            $table->integer('nameservers_per_client')->default(2)->after('subdomains_per_client');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('reseller_plans', function (Blueprint $table) {
            // Drop restored columns
            $table->dropColumn([
                'dns_zones_per_client',
                'subdomains_per_client',
                'nameservers_per_client'
            ]);

            // Add back new columns
            $table->integer('max_dns_zones')->nullable()->after('max_clients');
            $table->integer('max_subdomains')->nullable()->after('max_dns_zones');
            $table->json('allocated_nameservers')->nullable()->after('max_subdomains');
            $table->boolean('allow_import_export')->default(false)->after('allowed_record_types');
            $table->boolean('allow_api_access')->default(false)->after('allow_import_export');
            $table->boolean('allow_dyndns')->default(false)->after('allow_api_access');
            $table->integer('dyndns_limit')->nullable()->after('allow_dyndns');
        });
    }
};
