{% extends 'module.py.jinja2' -%}
{% macro render_param(param) %}
{{ param.name }}: {{ param.annotation.type.__repr__() }}{% if not param.required %} = lapis_client_base.absent.ABSENT{% endif %},
{% endmacro %}
{% block body -%}
{% set path = model.path -%}
{% set model = model.body -%}
class ApiClient(lapis_client_base.ApiBase):
{%- for func in model.methods %}
    async def {{ func.name }}(
        self,
    {% if func.request_type is not none %}request_body: {{ type_hint(func.request_type, path) }}, /, {% endif %}
    {% if func.params | length > 0 %}*, {% endif %}
    {% for param in func.params if param.required %}
        {{ render_param(param) }}
{%- endfor %}{% for param in func.params if not param.required %}
        {{ render_param(param) }}
{%- endfor %}) -> {{ type_hint(func.response_type, path) }}:
{%- if func.params_model_name %}
        import {{ func.params_model_name.module }}
{%- endif %}
        return await super()._request(
            '{{ func.method.upper() }}',
            f'{{ func.path }}'{% if func.params_model_name %},
            param_model={{ func.params_model_name.full_name() }}(**locals()){% endif %}, {% if func.response_class_map %}
            response_mapping={ {%- for code, media_type in func.response_class_map.items() %}
                '{{ code }}': { {%- for mime, typ in media_type.items() %}
                    '{{ mime }}': {{ typ.full_name() }},
                    {%- endfor %}
                },
            {%- endfor -%} }{%- endif %}
        )
{% else %}
    pass
{%- endfor %}
{%- endblock %}
