##
## This code was generated by snekrpc. Do not edit.
## Generated: {{ timestamp.isoformat() }}
##

{% for import in imports -%}
{{ import }}
{% endfor %}
import msgspec

import snekrpc

{% for class in classes %}
{{ class }}
{% endfor -%}

{% for service_name, spec in specs.items() %}
class {{ service_name }}:
    def __init__(self, proxy: snekrpc.service.ServiceProxy):
        self._proxy = proxy
{%- for command in spec.commands %}

    def {{ command.name }}{{ command.to_signature(include_self=True) }}:
    {%- if command.return_annotation == 'None' %}
        self._proxy.{{ command.name }}({{ command.parameters | join(', ', attribute='name') }})
    {%- elif command.is_generator %}
        res = self._proxy.{{ command.name }}({% for param in command.parameters -%} {{ param.name }} {%- endfor %})
        for r in res:
            yield msgspec.convert(r, type={{ command.return_annotation }})  # type: ignore
    {%- else %}
        res = self._proxy.{{ command.name }}({% for param in command.parameters -%} {{ param.name }} {%- endfor %})
        return msgspec.convert(res, type={{ command.return_annotation }})
{%- endif -%}

{% endfor %}
{% endfor %}

class Client(snekrpc.Client):
{%- for service_name, spec in specs.items() %}
    @property
    def {{ spec.name }}(self) -> {{ service_name }}:
        proxy = self.service('{{ spec.name }}')
        return {{ service_name }}(proxy)
{% endfor %}
