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

__all__ = (
    "TestStub",
    "TestBase",
)


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

import grpclib

import betterproto_fw
from betterproto_fw.grpc.grpclib_server import ServiceBase


if TYPE_CHECKING:
    import grpclib.server
    from grpclib.metadata import Deadline

    from betterproto_fw.grpc.grpclib_client import MetadataLike


class TestStub(betterproto_fw.ServiceStub):
    """ """

    async def do_thing(
        self,
        messages_do_thing_request: "_messages__.DoThingRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "_messages__.DoThingResponse":
        """ """

        return await self._unary_unary(
            "/service_separate_packages.things.service.Test/DoThing",
            messages_do_thing_request,
            _messages__.DoThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def do_many_things(
        self,
        messages_do_thing_request_iterator: "Union[AsyncIterable[_messages__.DoThingRequest], Iterable[_messages__.DoThingRequest]]",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "_messages__.DoThingResponse":
        """ """

        return await self._stream_unary(
            "/service_separate_packages.things.service.Test/DoManyThings",
            messages_do_thing_request_iterator,
            _messages__.DoThingRequest,
            _messages__.DoThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_thing_versions(
        self,
        messages_get_thing_request: "_messages__.GetThingRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "AsyncIterator[_messages__.GetThingResponse]":
        """ """

        async for response in self._unary_stream(
            "/service_separate_packages.things.service.Test/GetThingVersions",
            messages_get_thing_request,
            _messages__.GetThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    async def get_different_things(
        self,
        messages_get_thing_request_iterator: "Union[AsyncIterable[_messages__.GetThingRequest], Iterable[_messages__.GetThingRequest]]",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "AsyncIterator[_messages__.GetThingResponse]":
        """ """

        async for response in self._stream_stream(
            "/service_separate_packages.things.service.Test/GetDifferentThings",
            messages_get_thing_request_iterator,
            _messages__.GetThingRequest,
            _messages__.GetThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response


from .. import messages as _messages__


class TestBase(ServiceBase):
    """ """

    async def do_thing(
        self, messages_do_thing_request: "_messages__.DoThingRequest"
    ) -> "_messages__.DoThingResponse":
        """ """

        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def do_many_things(
        self,
        messages_do_thing_request_iterator: AsyncIterator[_messages__.DoThingRequest],
    ) -> "_messages__.DoThingResponse":
        """ """

        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_thing_versions(
        self, messages_get_thing_request: "_messages__.GetThingRequest"
    ) -> AsyncIterator[_messages__.GetThingResponse]:
        """ """

        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield _messages__.GetThingResponse()

    async def get_different_things(
        self,
        messages_get_thing_request_iterator: AsyncIterator[_messages__.GetThingRequest],
    ) -> AsyncIterator[_messages__.GetThingResponse]:
        """ """

        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield _messages__.GetThingResponse()

    async def __rpc_do_thing(
        self,
        stream: "grpclib.server.Stream[_messages__.DoThingRequest, _messages__.DoThingResponse]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.do_thing(request)
        await stream.send_message(response)

    async def __rpc_do_many_things(
        self,
        stream: "grpclib.server.Stream[_messages__.DoThingRequest, _messages__.DoThingResponse]",
    ) -> None:
        request = stream.__aiter__()
        response = await self.do_many_things(request)
        await stream.send_message(response)

    async def __rpc_get_thing_versions(
        self,
        stream: "grpclib.server.Stream[_messages__.GetThingRequest, _messages__.GetThingResponse]",
    ) -> None:
        request = await stream.recv_message()
        await self._call_rpc_handler_server_stream(
            self.get_thing_versions,
            stream,
            request,
        )

    async def __rpc_get_different_things(
        self,
        stream: "grpclib.server.Stream[_messages__.GetThingRequest, _messages__.GetThingResponse]",
    ) -> None:
        request = stream.__aiter__()
        await self._call_rpc_handler_server_stream(
            self.get_different_things,
            stream,
            request,
        )

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/service_separate_packages.things.service.Test/DoThing": grpclib.const.Handler(
                self.__rpc_do_thing,
                grpclib.const.Cardinality.UNARY_UNARY,
                _messages__.DoThingRequest,
                _messages__.DoThingResponse,
            ),
            "/service_separate_packages.things.service.Test/DoManyThings": grpclib.const.Handler(
                self.__rpc_do_many_things,
                grpclib.const.Cardinality.STREAM_UNARY,
                _messages__.DoThingRequest,
                _messages__.DoThingResponse,
            ),
            "/service_separate_packages.things.service.Test/GetThingVersions": grpclib.const.Handler(
                self.__rpc_get_thing_versions,
                grpclib.const.Cardinality.UNARY_STREAM,
                _messages__.GetThingRequest,
                _messages__.GetThingResponse,
            ),
            "/service_separate_packages.things.service.Test/GetDifferentThings": grpclib.const.Handler(
                self.__rpc_get_different_things,
                grpclib.const.Cardinality.STREAM_STREAM,
                _messages__.GetThingRequest,
                _messages__.GetThingResponse,
            ),
        }
