import {AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios";
import {ResourceAbstract} from "sdkgen-client"
{% for className in imports %}
import {{ '{' }}{{ className }}{{ '}' }} from "./{{ className }}";
{% endfor %}

export default class {{ className }} extends ResourceAbstract {
    private url: string;

{% for name, arg in properties %}
    private {{ name }}: {{ arg.type|raw }};
{% endfor %}

    public constructor({% for name, arg in properties %}{{ name }}: {{ arg.type|raw }}, {% endfor %}baseUrl: string, httpClient: AxiosInstance) {
        super(baseUrl, httpClient);

{% for name, arg in properties %}
        this.{{ name }} = {{ name }};
{% endfor %}

        this.url = 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 }}{{ '}' }} {{ name }}
{% endfor %}
     * @returns {{ '{' }}Promise<AxiosResponse<{% if method.return %}{{ method.return.docType|raw }}{% else %}void{% endif %}>>{{ '}' }}
     */
    public async {{ methodName }}({% for name, arg in method.args %}{{ name }}{% if arg.optional %}?{% endif %}: {{ arg.type|raw }}{% if not loop.last %}, {% endif %}{% endfor %}): Promise<AxiosResponse<{% if method.return %}{{ method.return.type|raw }}{% else %}void{% endif %}>> {
        let params: AxiosRequestConfig = {
            method: '{{ method.httpMethod }}',
{% if method.args.query is defined %}
            params: query,
{% endif %}
        };

{% if method.httpMethod in ['DELETE'] %}
        return this.httpClient.{{ method.httpMethod|lower }}(this.url, params);
{% elseif method.httpMethod in ['POST', 'PUT', 'PATCH'] %}
        return this.httpClient.{{ method.httpMethod|lower }}{% if method.return %}<{{ method.return.type }}>{% endif %}(this.url, {% if method.args.data is defined %}data{% else %}null{% endif %}, params);
{% else %}
        return this.httpClient.{{ method.httpMethod|lower }}{% if method.return %}<{{ method.return.type }}>{% endif %}(this.url, params);
{% endif %}
    }

{% endfor %}
}
