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

__all__ = (
    "ThingType",
    "DoThingRequest",
    "DoThingResponse",
    "GetThingRequest",
    "GetThingResponse",
    "TestStub",
    "TestBase",
)


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

import grpclib
from pydantic.dataclasses import dataclass

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 ThingType(betterproto_fw.Enum):
    """ """

    UNKNOWN = 0
    """
    
    """

    LIVING = 1
    """
    
    """

    DEAD = 2
    """
    
    """

    @classmethod
    def __get_pydantic_core_schema__(cls, _source_type, _handler):
        from pydantic_core import core_schema

        return core_schema.int_schema(ge=0)


@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class DoThingRequest(betterproto_fw.Message):
    """ """

    name: str = betterproto_fw.string_field(1)
    """
    
    """

    comments: List[str] = betterproto_fw.string_field(2)
    """
    
    """

    type: "ThingType" = betterproto_fw.enum_field(3)
    """
    
    """


@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class DoThingResponse(betterproto_fw.Message):
    """ """

    names: List[str] = betterproto_fw.string_field(1)
    """
    
    """


@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class GetThingRequest(betterproto_fw.Message):
    """ """

    name: str = betterproto_fw.string_field(1)
    """
    
    """


@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class GetThingResponse(betterproto_fw.Message):
    """ """

    name: str = betterproto_fw.string_field(1)
    """
    
    """

    version: int = betterproto_fw.int32_field(2)
    """
    
    """


class TestStub(betterproto_fw.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,
            ),
        }
