<?php

namespace Licenzo\Helper;

if (!defined('ABSPATH')) {
    exit;
}

class Action extends Hook
{

    public static function do($tag, ...$args)
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        return do_action(static::getTagWithPrefix($tag), ...$args);
    }

    public static function add($tag, $functionToAdd, $priority = 10, $acceptedArgs = 1)
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        return add_action(static::getTagWithPrefix($tag), $functionToAdd, $priority, $acceptedArgs);
    }

    public static function dispatch($action, $payload = [])
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        return do_action(static::getTagWithPrefix($action), $payload);
    }

    public static function listen($action, $callback, $priority = 10, $acceptedArgs = 1)
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        return add_action(static::getTagWithPrefix($action), $callback, $priority, $acceptedArgs);
    }

    public static function remove($tag, $functionToRemove, $priority = 10)
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        remove_action(static::getTagWithPrefix($tag), $functionToRemove, $priority);
    }

    public static function has($tag)
    {
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
        return has_action(static::getTagWithPrefix($tag));
    }
}
