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

__all__ = (
    "RequestMessage",
    "RequestResponse",
    "Nested",
    "NestedRequestMessage",
    "TestStub",
    "TestBase",
)


from typing import (
    TYPE_CHECKING,
    Dict,
    Optional,
)

import grpclib
from pydantic.dataclasses import dataclass

import betterproto
from betterproto.grpc.grpclib_server import ServiceBase


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

    from betterproto.grpc.grpclib_client import MetadataLike


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

    argument: int = betterproto.int32_field(1)
    """
    
    """


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

    value: int = betterproto.int32_field(1)
    """
    
    """


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

    pass


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

    nested_argument: int = betterproto.int32_field(1)
    """
    
    """


class TestStub(betterproto.ServiceStub):
    """Tests generated service correctly imports the RequestMessage"""

    async def do_thing(
        self,
        request_message: "RequestMessage",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "RequestResponse":
        """ """

        return await self._unary_unary(
            "/import_service_input_message.Test/DoThing",
            request_message,
            RequestResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def do_thing2(
        self,
        child_child_request_message: "child.ChildRequestMessage",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "RequestResponse":
        """ """

        return await self._unary_unary(
            "/import_service_input_message.Test/DoThing2",
            child_child_request_message,
            RequestResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def do_thing3(
        self,
        nested_request_message: "NestedRequestMessage",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "RequestResponse":
        """ """

        return await self._unary_unary(
            "/import_service_input_message.Test/DoThing3",
            nested_request_message,
            RequestResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


from . import child


class TestBase(ServiceBase):
    """Tests generated service correctly imports the RequestMessage"""

    async def do_thing(self, request_message: "RequestMessage") -> "RequestResponse":
        """ """

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

    async def do_thing2(
        self, child_child_request_message: "child.ChildRequestMessage"
    ) -> "RequestResponse":
        """ """

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

    async def do_thing3(
        self, nested_request_message: "NestedRequestMessage"
    ) -> "RequestResponse":
        """ """

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

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

    async def __rpc_do_thing2(
        self,
        stream: "grpclib.server.Stream[child.ChildRequestMessage, RequestResponse]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.do_thing2(request)
        await stream.send_message(response)

    async def __rpc_do_thing3(
        self, stream: "grpclib.server.Stream[NestedRequestMessage, RequestResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.do_thing3(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/import_service_input_message.Test/DoThing": grpclib.const.Handler(
                self.__rpc_do_thing,
                grpclib.const.Cardinality.UNARY_UNARY,
                RequestMessage,
                RequestResponse,
            ),
            "/import_service_input_message.Test/DoThing2": grpclib.const.Handler(
                self.__rpc_do_thing2,
                grpclib.const.Cardinality.UNARY_UNARY,
                child.ChildRequestMessage,
                RequestResponse,
            ),
            "/import_service_input_message.Test/DoThing3": grpclib.const.Handler(
                self.__rpc_do_thing3,
                grpclib.const.Cardinality.UNARY_UNARY,
                NestedRequestMessage,
                RequestResponse,
            ),
        }
