<?php

declare(strict_types=1);

namespace Plugin\tnt_stabila_shop\src\Helper;

use JTL\Shop;

class IOHelper
{
    /**
     * @param mixed ...$args
     * @throws \JsonException
     * @throws \Exception
     */
    public static function prepareIORequest(mixed ...$args): string
    {
        $params = $args[0] ?? [];
        if (\is_array($params) === false) {
            $params = [];
        }

        return Shop::getAdminURL()
            . '/io?token=' . (Shop::getAdminSessionToken() ?? '')
            . '&io=' . \urlencode(\json_encode([
                'name' => 'tntStabilaEndpoint',
                'params' => $params
            ], JSON_THROW_ON_ERROR));
    }
}
