# -*- coding: utf-8 -*-
# Generated by https://github.com/i2y/connecpy/protoc-gen-connecpy.  DO NOT EDIT!
# source: greeter.proto

from typing import Iterable, Mapping, Protocol

from connecpy.client import ConnecpyClient, ConnecpyClientSync
from connecpy.code import Code
from connecpy.exceptions import ConnecpyException
from connecpy.headers import Headers
from connecpy.server import (
    ConnecpyASGIApplication,
    ConnecpyWSGIApplication,
    Endpoint,
    ServerInterceptor,
    ServiceContext,
)
import greeter_pb2 as greeter__pb2


class Greeter(Protocol):
    async def SayHello(
        self, req: greeter__pb2.HelloRequest, ctx: ServiceContext
    ) -> greeter__pb2.HelloReply:
        raise ConnecpyException(Code.UNIMPLEMENTED, "Not implemented")


class GreeterASGIApplication(ConnecpyASGIApplication):
    def __init__(
        self,
        service: Greeter,
        *,
        interceptors: Iterable[ServerInterceptor] = (),
        max_receive_message_length=1024 * 100 * 100,
    ):
        super().__init__(
            endpoints={
                "/greeter.v1.Greeter/SayHello": Endpoint[
                    greeter__pb2.HelloRequest, greeter__pb2.HelloReply
                ](
                    service_name="Greeter",
                    name="SayHello",
                    function=getattr(service, "SayHello"),
                    input=greeter__pb2.HelloRequest,
                    output=greeter__pb2.HelloReply,
                    allowed_methods=("POST",),
                ),
            },
            interceptors=interceptors,
            max_receive_message_length=max_receive_message_length,
        )

    @property
    def path(self):
        """Returns the URL path to mount the application to when serving multiple applications."""
        return "/greeter.v1.Greeter"


class GreeterClient(ConnecpyClient):
    async def SayHello(
        self,
        request: greeter__pb2.HelloRequest,
        *,
        headers: Headers | Mapping[str, str] | None = None,
        timeout_ms: int | None = None,
    ) -> greeter__pb2.HelloReply:
        method = "POST"
        return await self._make_request(
            url="/greeter.v1.Greeter/SayHello",
            method=method,
            headers=headers,
            request=request,
            timeout_ms=timeout_ms,
            response_class=greeter__pb2.HelloReply,
        )


class GreeterSync(Protocol):
    def SayHello(
        self, req: greeter__pb2.HelloRequest, ctx: ServiceContext
    ) -> greeter__pb2.HelloReply:
        raise ConnecpyException(Code.UNIMPLEMENTED, "Not implemented")


class GreeterWSGIApplication(ConnecpyWSGIApplication):
    def __init__(self, service: GreeterSync):
        super().__init__(
            endpoints={
                "/greeter.v1.Greeter/SayHello": Endpoint[
                    greeter__pb2.HelloRequest, greeter__pb2.HelloReply
                ](
                    service_name="Greeter",
                    name="SayHello",
                    function=getattr(service, "SayHello"),
                    input=greeter__pb2.HelloRequest,
                    output=greeter__pb2.HelloReply,
                    allowed_methods=("POST",),
                ),
            }
        )

    @property
    def path(self):
        """Returns the URL path to mount the application to when serving multiple applications."""
        return "/greeter.v1.Greeter"


class GreeterClientSync(ConnecpyClientSync):
    def SayHello(
        self,
        request: greeter__pb2.HelloRequest,
        *,
        headers: Headers | Mapping[str, str] | None = None,
        timeout_ms: int | None = None,
    ) -> greeter__pb2.HelloReply:
        method = "POST"
        return self._make_request(
            url="/greeter.v1.Greeter/SayHello",
            method=method,
            headers=headers,
            timeout_ms=timeout_ms,
            request=request,
            response_class=greeter__pb2.HelloReply,
        )
