<?php

declare (strict_types=1);
namespace Worldline\Vendor\Worldline\WorldlineForWoocommerce\Webhooks;

use Worldline\Vendor\Worldline\Modularity\Module\ExecutableModule;
use Worldline\Vendor\Worldline\Modularity\Module\ModuleClassNameIdTrait;
use Worldline\Vendor\Worldline\Modularity\Module\ServiceModule;
use Worldline\Vendor\Psr\Container\ContainerInterface;
use Worldline\Vendor\Worldline\WorldlineForWoocommerce\WorldlinePaymentGateway\OrderMetaKeys;
use WP_REST_Request;
class WebhooksModule implements ExecutableModule, ServiceModule
{
    use ModuleClassNameIdTrait;
    /**
     * @inheritDoc
     */
    public function run(ContainerInterface $container) : bool
    {
        \add_action('rest_api_init', static function () use($container) {
            /** @var string $namespace */
            $namespace = $container->get('webhooks.namespace');
            /** @var string $route */
            $route = $container->get('webhooks.rest_route');
            /** @var string[] $methods */
            $methods = $container->get('webhooks.allowed_methods');
            /** @var callable $callback */
            $callback = $container->get('webhooks.callback');
            /** @var callable(): bool $permissionCallback */
            $permissionCallback = $container->get('webhooks.permission_callback');
            \register_rest_route($namespace, $route, ['methods' => $methods, 'callback' => $callback, 'permission_callback' => $permissionCallback]);
        });
        /** @var callable(WP_Rest_Request):void $logIncomingWebhookRequest */
        $logIncomingWebhookRequest = $container->get('webhooks.log_incoming_webhooks_request');
        \add_action('wlop.webhook_request', $logIncomingWebhookRequest);
        return \true;
    }
    /**
     * @inheritDoc
     */
    public function services() : array
    {
        static $services;
        if ($services === null) {
            $services = (require_once \dirname(__DIR__) . '/inc/services.php');
        }
        /** @var callable():
         * array<string, callable(ContainerInterface $container):mixed> $services
         */
        return $services();
    }
}
