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

use ShopyPress\Controllers\ShopifyCollectionsCtrl;
use ShopyPress\Controllers\ProductSyncCtrl;

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' => 'shopypress_fetch_collections', 'callback' => [ShopifyCollectionsCtrl::class, 'fetchCollections']],
            ['key' => 'shopypress_save_collection_selection', 'callback' => [ShopifyCollectionsCtrl::class, 'saveCollectionSelection']],
            ['key' => 'shopypress_save_collection_order', 'callback' => [ShopifyCollectionsCtrl::class, 'saveCollectionOrder']],
            ['key' => 'shopypress_start_product_sync', 'callback' => [ProductSyncCtrl::class, 'startSync']],
            ['key' => 'shopypress_get_sync_status', 'callback' => [ProductSyncCtrl::class, 'getSyncStatus']],
            ['key' => 'shopypress_reset_product_sync', 'callback' => [ProductSyncCtrl::class, 'resetSync']],
        ];
    }
}
