# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: gossip.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 client as __client__

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


class MemberInfoVNodeState(betterproto.Enum):
    Initializing = 0
    DiscoverLeader = 1
    Unknown = 2
    PreReplica = 3
    CatchingUp = 4
    Clone = 5
    Follower = 6
    PreLeader = 7
    Leader = 8
    Manager = 9
    ShuttingDown = 10
    Shutdown = 11
    ReadOnlyLeaderless = 12
    PreReadOnlyReplica = 13
    ReadOnlyReplica = 14
    ResigningLeader = 15


@dataclass(eq=False, repr=False)
class ClusterInfo(betterproto.Message):
    members: List["MemberInfo"] = betterproto.message_field(1)


@dataclass(eq=False, repr=False)
class EndPoint(betterproto.Message):
    address: str = betterproto.string_field(1)
    port: int = betterproto.uint32_field(2)


@dataclass(eq=False, repr=False)
class MemberInfo(betterproto.Message):
    instance_id: "__client__.Uuid" = betterproto.message_field(1)
    time_stamp: int = betterproto.int64_field(2)
    state: "MemberInfoVNodeState" = betterproto.enum_field(3)
    is_alive: bool = betterproto.bool_field(4)
    http_end_point: "EndPoint" = betterproto.message_field(5)


class GossipStub(betterproto.ServiceStub):
    async def read(
        self,
        client_empty: "__client__.Empty",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "ClusterInfo":
        return await self._unary_unary(
            "/event_store.client.gossip.Gossip/Read",
            client_empty,
            ClusterInfo,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class GossipBase(ServiceBase):
    async def read(self, client_empty: "__client__.Empty") -> "ClusterInfo":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_read(
        self, stream: "grpclib.server.Stream[__client__.Empty, ClusterInfo]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.read(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/event_store.client.gossip.Gossip/Read": grpclib.const.Handler(
                self.__rpc_read,
                grpclib.const.Cardinality.UNARY_UNARY,
                __client__.Empty,
                ClusterInfo,
            ),
        }
