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

from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    AsyncIterable,
    AsyncIterator,
    Dict,
    Iterable,
    List,
    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


class ThingType(betterproto.Enum):
    UNKNOWN = 0
    LIVING = 1
    DEAD = 2


@dataclass(eq=False, repr=False)
class DoThingRequest(betterproto.Message):
    name: str = betterproto.string_field(1)
    comments: List[str] = betterproto.string_field(2)
    type: "ThingType" = betterproto.enum_field(3)


@dataclass(eq=False, repr=False)
class DoThingResponse(betterproto.Message):
    names: List[str] = betterproto.string_field(1)


@dataclass(eq=False, repr=False)
class GetThingRequest(betterproto.Message):
    name: str = betterproto.string_field(1)


@dataclass(eq=False, repr=False)
class GetThingResponse(betterproto.Message):
    name: str = betterproto.string_field(1)
    version: int = betterproto.int32_field(2)


class TestStub(betterproto.ServiceStub):
    async def do_thing(
        self,
        do_thing_request: "DoThingRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "DoThingResponse":
        return await self._unary_unary(
            "/service.Test/DoThing",
            do_thing_request,
            DoThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def do_many_things(
        self,
        do_thing_request_iterator: Union[
            AsyncIterable[DoThingRequest], Iterable[DoThingRequest]
        ],
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "DoThingResponse":
        return await self._stream_unary(
            "/service.Test/DoManyThings",
            do_thing_request_iterator,
            DoThingRequest,
            DoThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_thing_versions(
        self,
        get_thing_request: "GetThingRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> AsyncIterator[GetThingResponse]:
        async for response in self._unary_stream(
            "/service.Test/GetThingVersions",
            get_thing_request,
            GetThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    async def get_different_things(
        self,
        get_thing_request_iterator: Union[
            AsyncIterable[GetThingRequest], Iterable[GetThingRequest]
        ],
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> AsyncIterator[GetThingResponse]:
        async for response in self._stream_stream(
            "/service.Test/GetDifferentThings",
            get_thing_request_iterator,
            GetThingRequest,
            GetThingResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response


class TestBase(ServiceBase):
    async def do_thing(self, do_thing_request: "DoThingRequest") -> "DoThingResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def do_many_things(
        self, do_thing_request_iterator: AsyncIterator[DoThingRequest]
    ) -> "DoThingResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_thing_versions(
        self, get_thing_request: "GetThingRequest"
    ) -> AsyncIterator[GetThingResponse]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield GetThingResponse()

    async def get_different_things(
        self, get_thing_request_iterator: AsyncIterator[GetThingRequest]
    ) -> AsyncIterator[GetThingResponse]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
        yield GetThingResponse()

    async def __rpc_do_thing(
        self, stream: "grpclib.server.Stream[DoThingRequest, 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[DoThingRequest, 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[GetThingRequest, 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[GetThingRequest, 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.Test/DoThing": grpclib.const.Handler(
                self.__rpc_do_thing,
                grpclib.const.Cardinality.UNARY_UNARY,
                DoThingRequest,
                DoThingResponse,
            ),
            "/service.Test/DoManyThings": grpclib.const.Handler(
                self.__rpc_do_many_things,
                grpclib.const.Cardinality.STREAM_UNARY,
                DoThingRequest,
                DoThingResponse,
            ),
            "/service.Test/GetThingVersions": grpclib.const.Handler(
                self.__rpc_get_thing_versions,
                grpclib.const.Cardinality.UNARY_STREAM,
                GetThingRequest,
                GetThingResponse,
            ),
            "/service.Test/GetDifferentThings": grpclib.const.Handler(
                self.__rpc_get_different_things,
                grpclib.const.Cardinality.STREAM_STREAM,
                GetThingRequest,
                GetThingResponse,
            ),
        }
