<?php
namespace OxygenApp\Hooks;
if ( ! defined( 'ABSPATH' ) ) exit;

use OxygenApp\Controllers\UserCtrl;

class ActionAjax implements IHook {

    static function register() {
        $actions = self::getActions();
        foreach ($actions as $action) {
            add_action('wp_ajax_' . $action['key'], $action['callback']);
            $supports_frontend = $action['supports_frontend'] ?? false;
            if ($supports_frontend) {
                add_action('wp_ajax_nopriv_' . $action['key'], $action['callback']);
            }
        }
    }

    static function getActions(): array {
        return [
            ['key' => 'oxygen_app_search_users', 'callback' => [UserCtrl::class, 'search']],
            ['key' => 'oxygen_app_update_user_field', 'callback' => [UserCtrl::class, 'updateUserField']],
            ['key' => 'oxygen_app_delete_user', 'callback' => [UserCtrl::class, 'deleteUser']],
        ];
    }
}