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

use FuseCommerce\Controllers\ProductsCtrl;
use FuseCommerce\Controllers\FiltersCtrl;

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' => 'fuse_comm_index_products', 'callback' => [ProductsCtrl::class, 'indexProducts']],
            ['key' => 'fuse_comm_reset_index', 'callback' => [ProductsCtrl::class, 'resetIndexing']],
            ['key' => 'fuse_comm_get_index_status', 'callback' => [ProductsCtrl::class, 'getIndexingStatus']],
            ['key' => 'fuse_comm_load_filter_config', 'callback' => [FiltersCtrl::class, 'loadFilterConfiguration']],
            ['key' => 'fuse_comm_save_filter_config', 'callback' => [FiltersCtrl::class, 'saveFilterConfiguration']],
        ];
    }
}