<?php

declare(strict_types=1);

namespace WPUltimateSecurity\UltimateSecurity\Modules\Maintenance;

use WPUltimateSecurity\UltimateSecurity\Modules\Base\AbstractModule;
use WPUltimateSecurity\UltimateSecurity\Support\Helpers\Utils;

class ImportExport extends AbstractModule
{
    public const MODULE_ID = 'maintenance.import_export';

    protected const VERSION = '2.0.0';

    /**
     * Get unique module identifier.
     */
    public static function getId(): string
    {
        return self::MODULE_ID;
    }

    /**
     * Get human-readable module name.
     */
    public static function getName(): string
    {
        return __('Import/Export', 'ultimate-security');
    }

    /**
     * Get module domain.
     */
    public static function getDomain(): string
    {
        return 'maintenance';
    }

    /**
     * Boot the module after registration.
     */
	public static function boot(): void
	{
		add_action('rest_api_init', [self::class, 'register_rest_routes']);
	}
	public static function register_rest_routes()
	{
		register_rest_route('ultimate-security/v1', '/settings', [
			'methods' => 'POST',
			'callback' => function ($request) {
				$data = $request->get_json_params();
				Utils::ultimate_security_update_option($data);
				return rest_ensure_response(['success' => true]);
			},
			// 'permission_callback' => '__return_true',
			'permission_callback' => function () {
				return current_user_can('manage_options');
			},
		]);
	}
}
