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

__all__ = (
    "RequestMessage",
    "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):
    """ """

    pass


class TestStub(betterproto.ServiceStub):
    """
    Tests that imports are generated correctly when returning Google well-known types
    """

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

        return await self._unary_unary(
            "/googletypes_service_returns_googletype.Test/GetEmpty",
            request_message,
            betterproto_lib_pydantic_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

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

        return await self._unary_unary(
            "/googletypes_service_returns_googletype.Test/GetStruct",
            request_message,
            betterproto_lib_pydantic_google_protobuf.Struct,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

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

        return await self._unary_unary(
            "/googletypes_service_returns_googletype.Test/GetListValue",
            request_message,
            betterproto_lib_pydantic_google_protobuf.ListValue,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

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

        return await self._unary_unary(
            "/googletypes_service_returns_googletype.Test/GetValue",
            request_message,
            betterproto_lib_pydantic_google_protobuf.Value,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


import betterproto.lib.pydantic.google.protobuf as betterproto_lib_pydantic_google_protobuf


class TestBase(ServiceBase):
    """
    Tests that imports are generated correctly when returning Google well-known types
    """

    async def get_empty(
        self, request_message: "RequestMessage"
    ) -> "betterproto_lib_pydantic_google_protobuf.Empty":
        """ """

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

    async def get_struct(
        self, request_message: "RequestMessage"
    ) -> "betterproto_lib_pydantic_google_protobuf.Struct":
        """ """

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

    async def get_list_value(
        self, request_message: "RequestMessage"
    ) -> "betterproto_lib_pydantic_google_protobuf.ListValue":
        """ """

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

    async def get_value(
        self, request_message: "RequestMessage"
    ) -> "betterproto_lib_pydantic_google_protobuf.Value":
        """ """

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

    async def __rpc_get_empty(
        self,
        stream: "grpclib.server.Stream[RequestMessage, betterproto_lib_pydantic_google_protobuf.Empty]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_empty(request)
        await stream.send_message(response)

    async def __rpc_get_struct(
        self,
        stream: "grpclib.server.Stream[RequestMessage, betterproto_lib_pydantic_google_protobuf.Struct]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_struct(request)
        await stream.send_message(response)

    async def __rpc_get_list_value(
        self,
        stream: "grpclib.server.Stream[RequestMessage, betterproto_lib_pydantic_google_protobuf.ListValue]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_list_value(request)
        await stream.send_message(response)

    async def __rpc_get_value(
        self,
        stream: "grpclib.server.Stream[RequestMessage, betterproto_lib_pydantic_google_protobuf.Value]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_value(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/googletypes_service_returns_googletype.Test/GetEmpty": grpclib.const.Handler(
                self.__rpc_get_empty,
                grpclib.const.Cardinality.UNARY_UNARY,
                RequestMessage,
                betterproto_lib_pydantic_google_protobuf.Empty,
            ),
            "/googletypes_service_returns_googletype.Test/GetStruct": grpclib.const.Handler(
                self.__rpc_get_struct,
                grpclib.const.Cardinality.UNARY_UNARY,
                RequestMessage,
                betterproto_lib_pydantic_google_protobuf.Struct,
            ),
            "/googletypes_service_returns_googletype.Test/GetListValue": grpclib.const.Handler(
                self.__rpc_get_list_value,
                grpclib.const.Cardinality.UNARY_UNARY,
                RequestMessage,
                betterproto_lib_pydantic_google_protobuf.ListValue,
            ),
            "/googletypes_service_returns_googletype.Test/GetValue": grpclib.const.Handler(
                self.__rpc_get_value,
                grpclib.const.Cardinality.UNARY_UNARY,
                RequestMessage,
                betterproto_lib_pydantic_google_protobuf.Value,
            ),
        }
