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

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 StartJobRequest(betterproto.Message):
    graph: "_graph__.Graph" = betterproto.message_field(1)
    inputs: "_graph__.StructValue" = betterproto.message_field(2)
    job_id: str = betterproto.string_field(3)


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


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


@dataclass(eq=False, repr=False)
class RunningJobsResponse(betterproto.Message):
    jobs: List["JobStatus"] = betterproto.message_field(1)


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


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


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


@dataclass(eq=False, repr=False)
class JobStatusResponse(betterproto.Message):
    status: "JobStatus" = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class Empty(betterproto.Message):
    """
    This is supposed to be `google.protobuf.Empty` but unfortunately there is
    no support for this in `betterproto` yet.
    """

    pass


@dataclass(eq=False, repr=False)
class JobStatus(betterproto.Message):
    id: str = betterproto.string_field(1)
    success: "Empty" = betterproto.message_field(2, group="status")
    running: "Empty" = betterproto.message_field(3, group="status")
    error: str = betterproto.string_field(4, group="status")


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


@dataclass(eq=False, repr=False)
class DeleteCompletedResponse(betterproto.Message):
    job_ids: List[str] = betterproto.string_field(1)
    """ids of deleted jobs"""


class JobControlStub(betterproto.ServiceStub):
    async def running_jobs(
        self,
        running_jobs_request: "RunningJobsRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "RunningJobsResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.jobs.JobControl/RunningJobs",
            running_jobs_request,
            RunningJobsResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def start_job(
        self,
        start_job_request: "StartJobRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "StartJobResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.jobs.JobControl/StartJob",
            start_job_request,
            StartJobResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def job_status(
        self,
        job_status_request: "JobStatusRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "JobStatusResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.jobs.JobControl/JobStatus",
            job_status_request,
            JobStatusResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def stop_job(
        self,
        stop_job_request: "StopJobRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "StopJobResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.jobs.JobControl/StopJob",
            stop_job_request,
            StopJobResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def delete_completed(
        self,
        delete_completed_request: "DeleteCompletedRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "DeleteCompletedResponse":
        return await self._unary_unary(
            "/tierkreis.v1alpha1.jobs.JobControl/DeleteCompleted",
            delete_completed_request,
            DeleteCompletedResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class JobControlBase(ServiceBase):

    async def running_jobs(
        self, running_jobs_request: "RunningJobsRequest"
    ) -> "RunningJobsResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def start_job(
        self, start_job_request: "StartJobRequest"
    ) -> "StartJobResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def job_status(
        self, job_status_request: "JobStatusRequest"
    ) -> "JobStatusResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def stop_job(self, stop_job_request: "StopJobRequest") -> "StopJobResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def delete_completed(
        self, delete_completed_request: "DeleteCompletedRequest"
    ) -> "DeleteCompletedResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_running_jobs(
        self, stream: "grpclib.server.Stream[RunningJobsRequest, RunningJobsResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.running_jobs(request)
        await stream.send_message(response)

    async def __rpc_start_job(
        self, stream: "grpclib.server.Stream[StartJobRequest, StartJobResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.start_job(request)
        await stream.send_message(response)

    async def __rpc_job_status(
        self, stream: "grpclib.server.Stream[JobStatusRequest, JobStatusResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.job_status(request)
        await stream.send_message(response)

    async def __rpc_stop_job(
        self, stream: "grpclib.server.Stream[StopJobRequest, StopJobResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.stop_job(request)
        await stream.send_message(response)

    async def __rpc_delete_completed(
        self,
        stream: "grpclib.server.Stream[DeleteCompletedRequest, DeleteCompletedResponse]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.delete_completed(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/tierkreis.v1alpha1.jobs.JobControl/RunningJobs": grpclib.const.Handler(
                self.__rpc_running_jobs,
                grpclib.const.Cardinality.UNARY_UNARY,
                RunningJobsRequest,
                RunningJobsResponse,
            ),
            "/tierkreis.v1alpha1.jobs.JobControl/StartJob": grpclib.const.Handler(
                self.__rpc_start_job,
                grpclib.const.Cardinality.UNARY_UNARY,
                StartJobRequest,
                StartJobResponse,
            ),
            "/tierkreis.v1alpha1.jobs.JobControl/JobStatus": grpclib.const.Handler(
                self.__rpc_job_status,
                grpclib.const.Cardinality.UNARY_UNARY,
                JobStatusRequest,
                JobStatusResponse,
            ),
            "/tierkreis.v1alpha1.jobs.JobControl/StopJob": grpclib.const.Handler(
                self.__rpc_stop_job,
                grpclib.const.Cardinality.UNARY_UNARY,
                StopJobRequest,
                StopJobResponse,
            ),
            "/tierkreis.v1alpha1.jobs.JobControl/DeleteCompleted": grpclib.const.Handler(
                self.__rpc_delete_completed,
                grpclib.const.Cardinality.UNARY_UNARY,
                DeleteCompletedRequest,
                DeleteCompletedResponse,
            ),
        }
