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

from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    AsyncIterator,
    Dict,
    Iterator,
    Optional,
)

import betterproto
import grpc
from betterproto.grpcstub.grpcio_client import SyncServiceStub
from betterproto.grpcstub.grpclib_server import ServiceBase


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


@dataclass(eq=False, repr=False)
class FunctionInvokeRequest(betterproto.Message):
    stub_id: str = betterproto.string_field(1)
    args: bytes = betterproto.bytes_field(2)
    headless: bool = betterproto.bool_field(3)


@dataclass(eq=False, repr=False)
class FunctionInvokeResponse(betterproto.Message):
    task_id: str = betterproto.string_field(1)
    output: str = betterproto.string_field(2)
    done: bool = betterproto.bool_field(3)
    exit_code: int = betterproto.int32_field(4)
    result: bytes = betterproto.bytes_field(5)


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


@dataclass(eq=False, repr=False)
class FunctionGetArgsResponse(betterproto.Message):
    ok: bool = betterproto.bool_field(1)
    args: bytes = betterproto.bytes_field(2)


@dataclass(eq=False, repr=False)
class FunctionSetResultRequest(betterproto.Message):
    task_id: str = betterproto.string_field(1)
    result: bytes = betterproto.bytes_field(2)


@dataclass(eq=False, repr=False)
class FunctionSetResultResponse(betterproto.Message):
    ok: bool = betterproto.bool_field(1)


@dataclass(eq=False, repr=False)
class FunctionMonitorRequest(betterproto.Message):
    task_id: str = betterproto.string_field(1)
    stub_id: str = betterproto.string_field(2)
    container_id: str = betterproto.string_field(3)


@dataclass(eq=False, repr=False)
class FunctionMonitorResponse(betterproto.Message):
    ok: bool = betterproto.bool_field(1)
    cancelled: bool = betterproto.bool_field(2)
    complete: bool = betterproto.bool_field(3)
    timed_out: bool = betterproto.bool_field(4)


@dataclass(eq=False, repr=False)
class FunctionScheduleRequest(betterproto.Message):
    stub_id: str = betterproto.string_field(1)
    when: str = betterproto.string_field(2)
    deployment_id: str = betterproto.string_field(3)


@dataclass(eq=False, repr=False)
class FunctionScheduleResponse(betterproto.Message):
    ok: bool = betterproto.bool_field(1)
    err_msg: str = betterproto.string_field(2)
    scheduled_job_id: str = betterproto.string_field(3)


class FunctionServiceStub(SyncServiceStub):
    def function_invoke(
        self, function_invoke_request: "FunctionInvokeRequest"
    ) -> Iterator["FunctionInvokeResponse"]:
        for response in self._unary_stream(
            "/function.FunctionService/FunctionInvoke",
            FunctionInvokeRequest,
            FunctionInvokeResponse,
        )(function_invoke_request):
            yield response

    def function_get_args(
        self, function_get_args_request: "FunctionGetArgsRequest"
    ) -> "FunctionGetArgsResponse":
        return self._unary_unary(
            "/function.FunctionService/FunctionGetArgs",
            FunctionGetArgsRequest,
            FunctionGetArgsResponse,
        )(function_get_args_request)

    def function_set_result(
        self, function_set_result_request: "FunctionSetResultRequest"
    ) -> "FunctionSetResultResponse":
        return self._unary_unary(
            "/function.FunctionService/FunctionSetResult",
            FunctionSetResultRequest,
            FunctionSetResultResponse,
        )(function_set_result_request)

    def function_monitor(
        self, function_monitor_request: "FunctionMonitorRequest"
    ) -> Iterator["FunctionMonitorResponse"]:
        for response in self._unary_stream(
            "/function.FunctionService/FunctionMonitor",
            FunctionMonitorRequest,
            FunctionMonitorResponse,
        )(function_monitor_request):
            yield response

    def function_schedule(
        self, function_schedule_request: "FunctionScheduleRequest"
    ) -> "FunctionScheduleResponse":
        return self._unary_unary(
            "/function.FunctionService/FunctionSchedule",
            FunctionScheduleRequest,
            FunctionScheduleResponse,
        )(function_schedule_request)
