<?php

declare(strict_types=1);

namespace ShieldX\WPCLI;

defined('ABSPATH') || exit;

final class AdminGate
{
    public static function requireManageOptions(): void
    {
        $capability = defined('SHIELDX_MANAGE_CAPABILITY') ? (string) SHIELDX_MANAGE_CAPABILITY : 'manage_options';
        if (!function_exists('current_user_can') || !current_user_can($capability)) {
            \WP_CLI::error('SHIELD-X WP-CLI commands require an administrator context. Re-run with --user=<admin> or an account that has ' . $capability . '.');
        }
    }

    public static function requireDestructiveDatabaseRestore(): void
    {
        self::requireManageOptions();

        if (is_callable(['\WP_CLI', 'check_admin'])) {
            call_user_func(['\WP_CLI', 'check_admin']);
        }
    }
}
