from typing import Any
from urllib.parse import urlencode


import httpx

from . import params
from . import queries
from . import requests
from . import responses


class APIClient(httpx.Client):
    {% for func in functions %}
    def {{ func.func_name }}(self{% if func.params %}, params: {{ func.params }}{% endif %}{% if func.body %}, body: {{ func.body }}{% endif %}{% if func.query %}, query: {{ func.query }} | None = None{% endif %}, **kwargs: Any) -> tuple[httpx.Response, {{ func.return }}]:
        url = "{{ func.url }}"
        {% if func.params %}
        url = url.format(**params)
        {% endif %}
        {% if func.query %}
        if query:
            url += "?" + urlencode(query)
        {% endif %}
        res = self.request(
            "{{ func.http_method }}",
            url{% if func.body %}, json=body{% endif %},
            **kwargs
        )
        res.raise_for_status()
        return res, res.json()

    {% endfor %}
