<?php

use {{ spec.title | caseUcfirst }}\Client;
{% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %}
use {{ spec.title | caseUcfirst }}\InputFile;
{% endif %}
use {{ spec.title | caseUcfirst }}\Services\{{ service.name | caseUcfirst }};
{% set added = [] %}
{% for parameter in method.parameters.all %}
{% if method == parameter.required %}
{% 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\{{parameter.enumName | caseUcfirst}};
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

$client = (new Client())
    {%~ if method.auth|length > 0 %}
    ->setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    {%~ for node in method.auth %}
    {%~ for key,header in node|keys %}
    ->set{{header}}('{{node[header]['x-appwrite']['demo'] | raw }}'){% if loop.last%};{% endif%} // {{node[header].description}}
    {%~ endfor %}
    {%~ endfor %}
    {%~ endif %}

${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client);

$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %});{% endif %}

    {%~ for parameter in method.parameters.all %}
    {{ parameter.name | caseCamel }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}::{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}(){% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %}{% if not parameter.required %} // optional{% endif %}

    {%~ endfor -%}
{% if method.parameters.all | length > 0 %});{% endif %}
