Weak hands cannot be planted, meager skills have no foundation. Shallow wisdom is futile, how can one hope for a good name?扰扰从役倦，屑屑身事微。少壮轻年月，迟暮惜光辉。
<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace DebugLogConfigTool\Classes;

use DebugLogConfigTool\Activator;
use DebugLogConfigTool\Request;
use DebugLogConfigTool\Router;

class AjaxHandler
{
    
    /**
     * AjaxHandler constructor.
     */
    public function boot()
    {
        add_action('wp_ajax_dlct_logs_admin', [$this, 'handleRequest']);
    }
    
    public function handleRequest()
    {
        $this->verify($_REQUEST);

        try {
            $result = Router::load('app/routes.php')->direct(Request::ajaxRoute(), Request::method());
        } catch (\Throwable $e) {
            error_log(sprintf(
                '[debug-log-config-tool] router dispatch failed: %s (route=%s method=%s)',
                $e->getMessage(),
                Request::ajaxRoute(),
                Request::method()
            ));
            wp_send_json_error(['message' => 'Internal error.'], 500);
        }

        if (is_array($result) && isset($result['ok']) && $result['ok'] === false) {
            error_log(sprintf(
                '[debug-log-config-tool] unknown route: reason=%s route=%s method=%s',
                $result['reason'],
                isset($result['route']) ? $result['route'] : '',
                isset($result['method']) ? $result['method'] : ''
            ));
            wp_send_json_error(['message' => 'Unknown action.'], 404);
        }
    }
    
    public function getAccessRole()
    {
        return apply_filters('DLCT_LOG_admin_access_role'