# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: example_service.proto
# plugin: python-betterproto
# This file has been @generated

from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    AsyncIterable,
    AsyncIterator,
    Dict,
    Iterable,
    Optional,
    Union,
)

import betterproto
import grpclib
from betterproto.grpc.grpclib_server import ServiceBase


if TYPE_CHECKING:
    import grpclib.server
    from betterproto.grpc.grpclib_client import MetadataLike
    from grpclib.metadata import Deadline


@dataclass(eq=False, repr=False)
class ExampleRequest(betterproto.Message):
    example_string: str = betterproto.string_field(1)
    example_integer: int = betterproto.int64_field(2)


@dataclass(eq=False, repr=False)
class ExampleResponse(betterproto.Message):
    example_string: str = betterproto.string_field(1)
    example_integer: int = betterproto.int64_field(2)


class TestStub(betterproto.ServiceStub):
    async def example_unary_unary(
        self,
        example_request: "ExampleRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "ExampleResponse":
        return await self._unary_unary(
            "/example_service.Test/ExampleUnaryUnary",
            example_request,
            ExampleResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def example_unary_stream(
        self,
        example_request: "ExampleRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> AsyncIterator[ExampleResponse]:
        async for response in self._unary_stream(
            "/example_service.Test/ExampleUnaryStream",
            example_request,
            ExampleResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    async def example_stream_unary(
        self,
        example_request_iterator: Union[
            AsyncIterable[ExampleRequest], Iterable[ExampleRequest]
        ],
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "ExampleResponse":
        return await self._stream_unary(
            "/example_service.Test/ExampleStreamUnary",
            example_request_iterator,
            ExampleRequest,
            ExampleResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def example_stream_stream(
        self,
        example_request_iterator: Union[
            AsyncIterable[ExampleRequest], Iterable[ExampleRequest]
        ],
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> AsyncIterator[ExampleResponse]:
        async for response in self._stream_stream(
            "/example_service.Test/ExampleStreamStream",
            example_request_iterator,
            ExampleRequest,
            ExampleResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response


class TestBase(ServiceBase):
    async def example_unary_unary(
        self, example_request: "ExampleRequest"
    ) -> "ExampleResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def example_unary_stream(
        self, example_request: "ExampleRequest"
    ) -> AsyncIterator[ExampleResponse]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield ExampleResponse()

    async def example_stream_unary(
        self, example_request_iterator: AsyncIterator[ExampleRequest]
    ) -> "ExampleResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def example_stream_stream(
        self, example_request_iterator: AsyncIterator[ExampleRequest]
    ) -> AsyncIterator[ExampleResponse]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield ExampleResponse()

    async def __rpc_example_unary_unary(
        self, stream: "grpclib.server.Stream[ExampleRequest, ExampleResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.example_unary_unary(request)
        await stream.send_message(response)

    async def __rpc_example_unary_stream(
        self, stream: "grpclib.server.Stream[ExampleRequest, ExampleResponse]"
    ) -> None:
        request = await stream.recv_message()
        await self._call_rpc_handler_server_stream(
            self.example_unary_stream,
            stream,
            request,
        )

    async def __rpc_example_stream_unary(
        self, stream: "grpclib.server.Stream[ExampleRequest, ExampleResponse]"
    ) -> None:
        request = stream.__aiter__()
        response = await self.example_stream_unary(request)
        await stream.send_message(response)

    async def __rpc_example_stream_stream(
        self, stream: "grpclib.server.Stream[ExampleRequest, ExampleResponse]"
    ) -> None:
        request = stream.__aiter__()
        await self._call_rpc_handler_server_stream(
            self.example_stream_stream,
            stream,
            request,
        )

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/example_service.Test/ExampleUnaryUnary": grpclib.const.Handler(
                self.__rpc_example_unary_unary,
                grpclib.const.Cardinality.UNARY_UNARY,
                ExampleRequest,
                ExampleResponse,
            ),
            "/example_service.Test/ExampleUnaryStream": grpclib.const.Handler(
                self.__rpc_example_unary_stream,
                grpclib.const.Cardinality.UNARY_STREAM,
                ExampleRequest,
                ExampleResponse,
            ),
            "/example_service.Test/ExampleStreamUnary": grpclib.const.Handler(
                self.__rpc_example_stream_unary,
                grpclib.const.Cardinality.STREAM_UNARY,
                ExampleRequest,
                ExampleResponse,
            ),
            "/example_service.Test/ExampleStreamStream": grpclib.const.Handler(
                self.__rpc_example_stream_stream,
                grpclib.const.Cardinality.STREAM_STREAM,
                ExampleRequest,
                ExampleResponse,
            ),
        }
