{% if namespace %}
namespace {{ namespace }};
{% endif %}

use GuzzleHttp\Client;
use PSX\Schema\SchemaManager;
use Sdkgen\Client\ResourceAbstract;

class {{ className }} extends ResourceAbstract
{
    private string $url;

{% for name, arg in properties %}
    private {{ arg.type }} ${{ name }};
{% endfor %}

    public function __construct({% for name, arg in properties %}{{ arg.type }} ${{ name }}, {% endfor %}string $baseUrl, ?Client $httpClient = null, ?SchemaManager $schemaManager = null)
    {
        parent::__construct($baseUrl, $httpClient, $schemaManager);

{% for name, arg in properties %}
        $this->{{ name }} = ${{ name }};
{% endfor %}
        $this->url = $this->baseUrl . '{% for part in urlParts %}/{% if part.type == 'variable' %}' . ${{ part.value }} . '{% else %}{{ part.value }}{% endif %}{{ url|raw }}{% endfor %}';
    }

{% for methodName, method in methods %}
    /**
{% if method.description %}     * {{ method.description }}
     *
{% endif %}
{% for name, arg in method.args %}     * @param {{ arg.docType }}{% if arg.optional %}|null{% endif %} ${{ name }}
{% endfor %}
     * @return {% if method.return %}{{ method.return.docType }}{% else %}void{% endif %}

     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function {{ methodName }}({% for name, arg in method.args %}{% if arg.optional %}?{% endif %}{{ arg.type }} ${{ name }}{% if arg.optional %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}): {% if method.return %}{{ method.return.type }}{% else %}void{% endif %}

    {
        $options = [
{% if method.args.query is defined %}
            'query' => $query !== null ? (array) $query->jsonSerialize() : [],
{% endif %}
{% if method.args.data is defined %}
            'json' => $data
{% endif %}
        ];

        $response = $this->httpClient->request('{{ method.httpMethod }}', $this->url, $options);
        $data     = (string) $response->getBody();

{% if method.return %}
        return $this->parse($data, {{ method.return.type }}::class);
{% endif %}
    }

{% endfor %}
}
