# 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

from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    Dict,
    Optional,
)

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

from . import child


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


@dataclass(eq=False, repr=False)
class RequestMessage(betterproto.Message):
    argument: int = betterproto.int32_field(1)


@dataclass(eq=False, repr=False)
class RequestResponse(betterproto.Message):
    value: int = betterproto.int32_field(1)


@dataclass(eq=False, repr=False)
class Nested(betterproto.Message):
    pass


@dataclass(eq=False, repr=False)
class NestedRequestMessage(betterproto.Message):
    nested_argument: int = betterproto.int32_field(1)


class TestStub(betterproto.ServiceStub):
    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,
        )


class TestBase(ServiceBase):
    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,
            ),
        }
