# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: v1alpha/runtime.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    Dict,
    List,
    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 RunTaskRequest(betterproto.Message):
    graph: "_graph__.Graph" = betterproto.message_field(1)
    inputs: "_graph__.StructValue" = betterproto.message_field(2)


@dataclass(eq=False, repr=False)
class RunTaskResponse(betterproto.Message):
    task_id: str = betterproto.string_field(1, group="result")
    type_errors: "_signature__.TypeErrors" = betterproto.message_field(
        2, group="result"
    )


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


@dataclass(eq=False, repr=False)
class ListTasksResponse(betterproto.Message):
    tasks: List["Task"] = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class DeleteTaskRequest(betterproto.Message):
    id: str = betterproto.string_field(1)


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


@dataclass(eq=False, repr=False)
class GetTaskRequest(betterproto.Message):
    id: str = betterproto.string_field(1)


@dataclass(eq=False, repr=False)
class GetTaskResponse(betterproto.Message):
    task: "Task" = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class AwaitTaskRequest(betterproto.Message):
    id: str = betterproto.string_field(1)
    timeout: int = betterproto.uint64_field(2)


@dataclass(eq=False, repr=False)
class AwaitTaskResponse(betterproto.Message):
    task: "Task" = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class Task(betterproto.Message):
    id: str = betterproto.string_field(1)
    success: "_graph__.StructValue" = betterproto.message_field(2, group="status")
    error: str = betterproto.string_field(3, group="status")


@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 list_tasks(
        self,
        list_tasks_request: "ListTasksRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "ListTasksResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha.runtime.Runtime/ListTasks",
            list_tasks_request,
            ListTasksResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def run_task(
        self,
        run_task_request: "RunTaskRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "RunTaskResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha.runtime.Runtime/RunTask",
            run_task_request,
            RunTaskResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_task(
        self,
        get_task_request: "GetTaskRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "GetTaskResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha.runtime.Runtime/GetTask",
            get_task_request,
            GetTaskResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def await_task(
        self,
        await_task_request: "AwaitTaskRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "AwaitTaskResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha.runtime.Runtime/AwaitTask",
            await_task_request,
            AwaitTaskResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def delete_task(
        self,
        delete_task_request: "DeleteTaskRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "DeleteTaskResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha.runtime.Runtime/DeleteTask",
            delete_task_request,
            DeleteTaskResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    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.v1alpha.runtime.Runtime/RunGraph",
            run_graph_request,
            RunGraphResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class RuntimeBase(ServiceBase):
    async def list_tasks(
        self, list_tasks_request: "ListTasksRequest"
    ) -> "ListTasksResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def run_task(self, run_task_request: "RunTaskRequest") -> "RunTaskResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_task(self, get_task_request: "GetTaskRequest") -> "GetTaskResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def await_task(
        self, await_task_request: "AwaitTaskRequest"
    ) -> "AwaitTaskResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def delete_task(
        self, delete_task_request: "DeleteTaskRequest"
    ) -> "DeleteTaskResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

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

    async def __rpc_list_tasks(
        self, stream: "grpclib.server.Stream[ListTasksRequest, ListTasksResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.list_tasks(request)
        await stream.send_message(response)

    async def __rpc_run_task(
        self, stream: "grpclib.server.Stream[RunTaskRequest, RunTaskResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.run_task(request)
        await stream.send_message(response)

    async def __rpc_get_task(
        self, stream: "grpclib.server.Stream[GetTaskRequest, GetTaskResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_task(request)
        await stream.send_message(response)

    async def __rpc_await_task(
        self, stream: "grpclib.server.Stream[AwaitTaskRequest, AwaitTaskResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.await_task(request)
        await stream.send_message(response)

    async def __rpc_delete_task(
        self, stream: "grpclib.server.Stream[DeleteTaskRequest, DeleteTaskResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.delete_task(request)
        await stream.send_message(response)

    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.v1alpha.runtime.Runtime/ListTasks": grpclib.const.Handler(
                self.__rpc_list_tasks,
                grpclib.const.Cardinality.UNARY_UNARY,
                ListTasksRequest,
                ListTasksResponse,
            ),
            "/tierkreis.v1alpha.runtime.Runtime/RunTask": grpclib.const.Handler(
                self.__rpc_run_task,
                grpclib.const.Cardinality.UNARY_UNARY,
                RunTaskRequest,
                RunTaskResponse,
            ),
            "/tierkreis.v1alpha.runtime.Runtime/GetTask": grpclib.const.Handler(
                self.__rpc_get_task,
                grpclib.const.Cardinality.UNARY_UNARY,
                GetTaskRequest,
                GetTaskResponse,
            ),
            "/tierkreis.v1alpha.runtime.Runtime/AwaitTask": grpclib.const.Handler(
                self.__rpc_await_task,
                grpclib.const.Cardinality.UNARY_UNARY,
                AwaitTaskRequest,
                AwaitTaskResponse,
            ),
            "/tierkreis.v1alpha.runtime.Runtime/DeleteTask": grpclib.const.Handler(
                self.__rpc_delete_task,
                grpclib.const.Cardinality.UNARY_UNARY,
                DeleteTaskRequest,
                DeleteTaskResponse,
            ),
            "/tierkreis.v1alpha.runtime.Runtime/RunGraph": grpclib.const.Handler(
                self.__rpc_run_graph,
                grpclib.const.Cardinality.UNARY_UNARY,
                RunGraphRequest,
                RunGraphResponse,
            ),
        }
