# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: v1alpha1/worker.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__,
    runtime as _runtime__,
)


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


@dataclass(eq=False, repr=False)
class RunFunctionRequest(betterproto.Message):
    function: "_graph__.FunctionName" = betterproto.message_field(1)
    inputs: "_graph__.StructValue" = betterproto.message_field(2)
    loc: "_graph__.Location" = betterproto.message_field(3)
    callback: "_runtime__.Callback" = betterproto.message_field(4)


@dataclass(eq=False, repr=False)
class RunFunctionResponse(betterproto.Message):
    outputs: "_graph__.StructValue" = betterproto.message_field(1)


class WorkerStub(betterproto.ServiceStub):
    async def run_function(
        self,
        run_function_request: "RunFunctionRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "RunFunctionResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.worker.Worker/RunFunction",
            run_function_request,
            RunFunctionResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class WorkerBase(ServiceBase):

    async def run_function(
        self, run_function_request: "RunFunctionRequest"
    ) -> "RunFunctionResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_run_function(
        self, stream: "grpclib.server.Stream[RunFunctionRequest, RunFunctionResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.run_function(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/tierkreis.v1alpha1.worker.Worker/RunFunction": grpclib.const.Handler(
                self.__rpc_run_function,
                grpclib.const.Cardinality.UNARY_UNARY,
                RunFunctionRequest,
                RunFunctionResponse,
            ),
        }
