<?php

namespace Alsendo\AlsendoWrapper;
use Alsendo\AlsendoWrapper\Exception\UnsupportedEndpointException;
use Exception;
use GuzzleHttp\Exception\GuzzleException;

abstract class ApiKeyClient extends ApiClient
{
    private array $supportedEndpoints = [
    ];

    /**
     * Sends a GET request to the specified endpoint with optional query parameters and authentication headers.
     *
     * @param string $endpoint The API endpoint path to request.
     * @param array $params Optional query parameters to include in the request URL.
     *
     * @return string The response data returned by the API as string.
     *
     * @throws GuzzleException|Exception|\GuzzleHttp\Exception\GuzzleException
     * @throws UnsupportedEndpointException If the API does not support the requested endpoint.
     */
    public function get(string $endpoint, array $params = []): string
    {
        if (!in_array($endpoint, $this->supportedEndpoints, true)) {
            throw new UnsupportedEndpointException($endpoint);
        }

        $options = [
            'query' => $params,
            'headers' => [
                'Authorization' => 'Bearer ' . $this->config['api_key'],
            ],
        ];

        return $this->makeRequest('GET', $endpoint, $options);
    }
}
