# This file has been generated - DO NOT MODIFY
# API Version : {{api_version}}


{#

Take inspiration from:

- https://github.com/openapi-generators/openapi-python-client/blob/main/openapi_python_client/templates/endpoint_module.py.jinja

#}


{% macro to_arguments(parameters) %}
{% for parameter in parameters %}
    {{ parameter.to_argument() }}
{% endfor %}
{% endmacro %}

{% macro query_parameters_as_dict(parameters) %}
{% for parameter in parameters%}
    {{parameter.name}}={{parameter.name}},
{% endfor%}
{% endmacro %}

{% macro return_statement(operation) %}

{% if operation.response_model.name %}
{% if operation.name in get_job_methods %}
return self.client.get_job(
    response_cls={{operation.response_model.name}},
    per_request_timeout=per_request_timeout,
    **kwargs
    )
{% elif operation.response_model.type == "array" %}
return [{{ operation.response_model.name }}(**item) for item in self.client.request(**kwargs)]
{% else %}
return {{operation.response_model.name}}(**self.client.request(**kwargs))
{% endif %}
{% else %}
return  self.client.request(**kwargs)
{% endif %}

{% endmacro %}


{% macro explode_form_data(operation) %}
    {% if operation.request_body.content_type == "multipart/form-data" %}
        request: Union[StringIO, BytesIO],
        {%- for parameter in operation.request_body.properties %}
            {% if parameter.name != "file" %}
                {{ parameter.to_argument() }}

            {% endif %}
        {% endfor %}

    {% else %}
        request: {{operation.request_body.model_name}},
    {% endif %}
{% endmacro %}

import logging


{% for model in models %}
from avatars.models import {{model}} # noqa: F401
{% endfor %}
from avatars.models import FileType

from io import StringIO, BytesIO
from typing import TYPE_CHECKING, Any, Dict, Optional, TypeVar, Union, List

if TYPE_CHECKING:
    from avatars.client import ApiClient


logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
DEFAULT_RETRY_TIMEOUT = 60
DEFAULT_TIMEOUT = 60


T = TypeVar('T')


{% set get_job_methods = ["get_advice","get_privacy_metrics", "get_signal_metrics", "get_avatarization_job", "get_avatarization_batch_job", "get_privacy_metrics_batch_job", "get_signal_metrics_batch_job", "get_avatarization_time_series_job", "get_signal_metrics_time_series_job", "get_privacy_metrics_time_series_job", "get_avatarization_multi_table_job", "get_privacy_metrics_multi_table_job", "get_privacy_metrics_geolocation_job"] %}
{% set methods_with_streaming = ["download_dataset_as_stream"] %}
{% set methods_without_auth_verification = ["login", "reset_password", "forgotten_password", "is_client_compatible"] %}
{% for tag, ops in operations|groupby("tag") %}

class {{tag|to_pascal_case}}:
    def __init__(self, client: "ApiClient") -> None:
        self.client = client
    {% for operation in ops %}

    def {{ operation.name }}(
        self,
        {% if operation.request_body.model_name or operation.request_body.content_type == "multipart/form-data" %}
        {{explode_form_data(operation)}}
        {% endif %}
        {{ to_arguments(operation.path_parameters) | indent(8) }}
        {{ to_arguments(operation.query_parameters) | indent(8) }}
        *,
        {% if operation.name in get_job_methods %}
        per_request_timeout : Optional[int] = DEFAULT_TIMEOUT,
        {% endif %}
        timeout : Optional[int] = DEFAULT_TIMEOUT,
            ) -> {% if operation.response_model %} {{ operation.response_model.type_hint() }} {% else %} Any {%endif%}:
    {% if operation.description %}
        """{{ operation.description|indent(8) }}
        """
    {% endif %}

        kwargs: Dict[str, Any] = {
            "method": "{{ operation.method }}",
            "url": f"{{ operation.url}}", # noqa: F541
            "timeout": timeout,

            {% if operation.query_parameters %}
            "params": dict({{query_parameters_as_dict(operation.query_parameters)}}),
            {% endif %}

            {% if operation.request_body.content_type == "multipart/form-data" %}
                "file" : request,
                {%- if operation.request_body.properties|length > 1 %}
                    {# We have additional form data fields alongside 'file', so we explode those. #}
                "form_data" : dict(
                {% for parameter in operation.request_body.properties %}
                    {% if parameter.name != "file" %}
                        {{parameter.name}}={{parameter.name}},
                    {% endif %}
                {% endfor %}
                )
                {% endif %}
            {% elif operation.request_body.content_type == "application/json" %}
            "json_data" : request,
            {% elif operation.request_body.content_type == "application/x-www-form-urlencoded" %}
            "form_data" : request,
            {% endif %}

            {% if operation.name in methods_with_streaming %}
            "should_stream" : True,
            {% endif %}
            {% if operation.name in methods_without_auth_verification %}
            "should_verify_auth" : False,
            {% endif %}
        }

        {{return_statement(operation) | indent(8)}}
    {% endfor %}
{% endfor %}
