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

use Sdkgen\Client\ClientAbstract;
use Sdkgen\Client\Credentials;
use Sdkgen\Client\CredentialsInterface;
use Sdkgen\Client\TokenStoreInterface;

class Client extends ClientAbstract
{
    public function __construct(string $baseUrl, {% if security.type == 'httpBasic' %}string $userName, string $password, {% elseif security.type in ['httpBearer', 'apiKey'] %}string $token, {% elseif security.type in ['clientCredentials', 'authorizationCode'] %}string $clientId, string $clientSecret, {% else %}?CredentialsInterface $credentials = null, {% endif %}?TokenStoreInterface $tokenStore = null, ?array $scopes = null)
    {
        parent::__construct($baseUrl, {% if security.type == 'httpBasic' %}new Credentials\HttpBasic($userName, $password){% elseif security.type == 'httpBearer' %}new Credentials\HttpBearer($token){% elseif security.type == 'apiKey' %}new Credentials\ApiKey($token, '{{ security.name }}', '{{ security.in }}'){% elseif security.type == 'clientCredentials' %}new Credentials\ClientCredentials($clientId, $clientSecret, '{{ security.tokenUrl }}', '{{ security.authorizationUrl }}', '{{ security.refreshUrl }}'){% elseif security.type == 'authorizationCode' %}new Credentials\AuthorizationCode($clientId, $clientSecret, '{{ security.tokenUrl }}', '{{ security.authorizationUrl }}', '{{ security.refreshUrl }}'){% else %}$credentials{% endif %}, $tokenStore, $scopes);
    }

{% for className, resource in resources %}
    /**
     * {{ resource.description|raw }}
     */
    public function {{ resource.methodName }}({% for name, arg in resource.properties %}{{ arg.type }} ${{ name }}{% if not loop.last %}, {% endif %}{% endfor %}): {{ className }}
    {
        return new {{ className }}(
            {% for name, arg in resource.properties %}${{ name }},
            {% endfor %}
$this->baseUrl,
            $this->newHttpClient(),
            $this->schemaManager
        );
    }

{% endfor %}
}
