# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: operations.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import Dict

import betterproto
import grpclib
from betterproto.grpc.grpclib_server import ServiceBase


class ScavengeRespScavengeResult(betterproto.Enum):
    Started = 0
    InProgress = 1
    Stopped = 2


@dataclass(eq=False, repr=False)
class StartScavengeReq(betterproto.Message):
    options: "StartScavengeReqOptions" = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class StartScavengeReqOptions(betterproto.Message):
    thread_count: int = betterproto.int32_field(1)
    start_from_chunk: int = betterproto.int32_field(2)


@dataclass(eq=False, repr=False)
class StopScavengeReq(betterproto.Message):
    options: "StopScavengeReqOptions" = betterproto.message_field(1)


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


@dataclass(eq=False, repr=False)
class ScavengeResp(betterproto.Message):
    scavenge_id: str = betterproto.string_field(1)
    scavenge_result: "ScavengeRespScavengeResult" = betterproto.enum_field(2)


@dataclass(eq=False, repr=False)
class SetNodePriorityReq(betterproto.Message):
    priority: int = betterproto.int32_field(1)


class OperationsStub(betterproto.ServiceStub):
    async def start_scavenge(
        self, *, options: "StartScavengeReqOptions" = None
    ) -> "ScavengeResp":

        request = StartScavengeReq()
        if options is not None:
            request.options = options

        return await self._unary_unary(
            "/event_store.client.operations.Operations/StartScavenge",
            request,
            ScavengeResp,
        )

    async def stop_scavenge(
        self, *, options: "StopScavengeReqOptions" = None
    ) -> "ScavengeResp":

        request = StopScavengeReq()
        if options is not None:
            request.options = options

        return await self._unary_unary(
            "/event_store.client.operations.Operations/StopScavenge",
            request,
            ScavengeResp,
        )

    async def shutdown(self) -> "__client__.Empty":

        request = __client__.Empty()

        return await self._unary_unary(
            "/event_store.client.operations.Operations/Shutdown",
            request,
            __client__.Empty,
        )

    async def merge_indexes(self) -> "__client__.Empty":

        request = __client__.Empty()

        return await self._unary_unary(
            "/event_store.client.operations.Operations/MergeIndexes",
            request,
            __client__.Empty,
        )

    async def resign_node(self) -> "__client__.Empty":

        request = __client__.Empty()

        return await self._unary_unary(
            "/event_store.client.operations.Operations/ResignNode",
            request,
            __client__.Empty,
        )

    async def set_node_priority(self, *, priority: int = 0) -> "__client__.Empty":

        request = SetNodePriorityReq()
        request.priority = priority

        return await self._unary_unary(
            "/event_store.client.operations.Operations/SetNodePriority",
            request,
            __client__.Empty,
        )

    async def restart_persistent_subscriptions(self) -> "__client__.Empty":

        request = __client__.Empty()

        return await self._unary_unary(
            "/event_store.client.operations.Operations/RestartPersistentSubscriptions",
            request,
            __client__.Empty,
        )


class OperationsBase(ServiceBase):
    async def start_scavenge(
        self, options: "StartScavengeReqOptions"
    ) -> "ScavengeResp":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def stop_scavenge(self, options: "StopScavengeReqOptions") -> "ScavengeResp":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def shutdown(self) -> "__client__.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def merge_indexes(self) -> "__client__.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def resign_node(self) -> "__client__.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def set_node_priority(self, priority: int) -> "__client__.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def restart_persistent_subscriptions(self) -> "__client__.Empty":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_start_scavenge(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "options": request.options,
        }

        response = await self.start_scavenge(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_stop_scavenge(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "options": request.options,
        }

        response = await self.stop_scavenge(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_shutdown(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {}

        response = await self.shutdown(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_merge_indexes(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {}

        response = await self.merge_indexes(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_resign_node(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {}

        response = await self.resign_node(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_set_node_priority(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "priority": request.priority,
        }

        response = await self.set_node_priority(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_restart_persistent_subscriptions(
        self, stream: grpclib.server.Stream
    ) -> None:
        request = await stream.recv_message()

        request_kwargs = {}

        response = await self.restart_persistent_subscriptions(**request_kwargs)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/event_store.client.operations.Operations/StartScavenge": grpclib.const.Handler(
                self.__rpc_start_scavenge,
                grpclib.const.Cardinality.UNARY_UNARY,
                StartScavengeReq,
                ScavengeResp,
            ),
            "/event_store.client.operations.Operations/StopScavenge": grpclib.const.Handler(
                self.__rpc_stop_scavenge,
                grpclib.const.Cardinality.UNARY_UNARY,
                StopScavengeReq,
                ScavengeResp,
            ),
            "/event_store.client.operations.Operations/Shutdown": grpclib.const.Handler(
                self.__rpc_shutdown,
                grpclib.const.Cardinality.UNARY_UNARY,
                __client__.Empty,
                __client__.Empty,
            ),
            "/event_store.client.operations.Operations/MergeIndexes": grpclib.const.Handler(
                self.__rpc_merge_indexes,
                grpclib.const.Cardinality.UNARY_UNARY,
                __client__.Empty,
                __client__.Empty,
            ),
            "/event_store.client.operations.Operations/ResignNode": grpclib.const.Handler(
                self.__rpc_resign_node,
                grpclib.const.Cardinality.UNARY_UNARY,
                __client__.Empty,
                __client__.Empty,
            ),
            "/event_store.client.operations.Operations/SetNodePriority": grpclib.const.Handler(
                self.__rpc_set_node_priority,
                grpclib.const.Cardinality.UNARY_UNARY,
                SetNodePriorityReq,
                __client__.Empty,
            ),
            "/event_store.client.operations.Operations/RestartPersistentSubscriptions": grpclib.const.Handler(
                self.__rpc_restart_persistent_subscriptions,
                grpclib.const.Cardinality.UNARY_UNARY,
                __client__.Empty,
                __client__.Empty,
            ),
        }


from ... import client as __client__
