<?php

namespace {{ spec.title | caseUcfirst }}\Services;

use {{ spec.title | caseUcfirst }}\{{spec.title | caseUcfirst}}Exception;
use {{ spec.title | caseUcfirst }}\Client;
use {{ spec.title | caseUcfirst }}\Service;
use {{ spec.title | caseUcfirst }}\InputFile;
{% set added = [] %}
{% for method in service.methods %}
{% for parameter in method.parameters.all %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
use {{ spec.title | caseUcfirst }}\Enums\{{ name | caseUcfirst }};
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

class {{ service.name | caseUcfirst }} extends Service
{
     public function __construct(Client $client)
     {
         parent::__construct($client);
     }

{% for method in service.methods %}
    /**
     * {{ method.title }}
     *
{% if method.description %}
{{ method.description|comment1 }}
     *
{% endif %}
{% for parameter in method.parameters.all %}
     * @param {% if not parameter.required or parameter.nullable %}?{% endif %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}
{% endfor %}
     * @throws {{spec.title | caseUcfirst}}Exception
     * @return {{ method | getReturn }}
     */
    public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if not parameter.required or parameter.nullable %}?{% endif %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
    {
        $apiPath = str_replace(
            [{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}],
            [{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}],
            '{{ method.path }}'
        );

        {{~ include('php/base/params.twig') -}}
        {%~ if 'multipart/form-data' in method.consumes %}
        {{~ include('php/base/requests/file.twig') }}
        {%~ else %}

        {{~ include('php/base/requests/api.twig') }}
        {%~ endif %}
    }
        {%~ if not loop.last %}

        {%~ endif %}
        {%~ endfor %}
}