# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: v1alpha1/runtime.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 (
    graph as _graph__,
    signature as _signature__,
)


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


@dataclass(eq=False, repr=False)
class Callback(betterproto.Message):
    uri: str = betterproto.string_field(1)
    loc: "_graph__.Location" = betterproto.message_field(2)


@dataclass(eq=False, repr=False)
class RunGraphRequest(betterproto.Message):
    graph: "_graph__.Graph" = betterproto.message_field(1)
    inputs: "_graph__.StructValue" = betterproto.message_field(2)
    type_check: bool = betterproto.bool_field(3)
    loc: "_graph__.Location" = betterproto.message_field(4)
    escape: "Callback" = betterproto.message_field(5)


@dataclass(eq=False, repr=False)
class RunGraphResponse(betterproto.Message):
    success: "_graph__.StructValue" = betterproto.message_field(1, group="result")
    error: str = betterproto.string_field(2, group="result")
    type_errors: "_signature__.TypeErrors" = betterproto.message_field(
        3, group="result"
    )


class RuntimeStub(betterproto.ServiceStub):
    async def run_graph(
        self,
        run_graph_request: "RunGraphRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "RunGraphResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.runtime.Runtime/RunGraph",
            run_graph_request,
            RunGraphResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class RuntimeBase(ServiceBase):

    async def run_graph(
        self, run_graph_request: "RunGraphRequest"
    ) -> "RunGraphResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_run_graph(
        self, stream: "grpclib.server.Stream[RunGraphRequest, RunGraphResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.run_graph(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/tierkreis.v1alpha1.runtime.Runtime/RunGraph": grpclib.const.Handler(
                self.__rpc_run_graph,
                grpclib.const.Cardinality.UNARY_UNARY,
                RunGraphRequest,
                RunGraphResponse,
            ),
        }
