# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: app/stats/command/command.proto
# plugin: python-betterproto2
# This file has been @generated

__all__ = (
    "Config",
    "GetStatsOnlineIpListResponse",
    "GetStatsRequest",
    "GetStatsResponse",
    "QueryStatsRequest",
    "QueryStatsResponse",
    "Stat",
    "SysStatsRequest",
    "SysStatsResponse",
    "StatsServiceStub",
    "StatsServiceBase",
)

from dataclasses import dataclass
from typing import TYPE_CHECKING

import betterproto2
import grpclib
from betterproto2.grpc.grpclib_server import ServiceBase

from .....message_pool import default_message_pool

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

betterproto2.check_compiler_version("0.5.1")


@dataclass(eq=False, repr=False)
class Config(betterproto2.Message):
    pass


default_message_pool.register_message("xray.app.stats.command", "Config", Config)


@dataclass(eq=False, repr=False)
class GetStatsOnlineIpListResponse(betterproto2.Message):
    name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)

    ips: "dict[str, int]" = betterproto2.field(
        2,
        betterproto2.TYPE_MAP,
        map_meta=betterproto2.map_meta(
            betterproto2.TYPE_STRING, betterproto2.TYPE_INT64
        ),
    )


default_message_pool.register_message(
    "xray.app.stats.command",
    "GetStatsOnlineIpListResponse",
    GetStatsOnlineIpListResponse,
)


@dataclass(eq=False, repr=False)
class GetStatsRequest(betterproto2.Message):
    name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
    """
    Name of the stat counter.
    """

    reset: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
    """
    Whether or not to reset the counter to fetching its value.
    """


default_message_pool.register_message(
    "xray.app.stats.command", "GetStatsRequest", GetStatsRequest
)


@dataclass(eq=False, repr=False)
class GetStatsResponse(betterproto2.Message):
    stat: "Stat | None" = betterproto2.field(
        1, betterproto2.TYPE_MESSAGE, optional=True
    )


default_message_pool.register_message(
    "xray.app.stats.command", "GetStatsResponse", GetStatsResponse
)


@dataclass(eq=False, repr=False)
class QueryStatsRequest(betterproto2.Message):
    pattern: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)

    reset: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)


default_message_pool.register_message(
    "xray.app.stats.command", "QueryStatsRequest", QueryStatsRequest
)


@dataclass(eq=False, repr=False)
class QueryStatsResponse(betterproto2.Message):
    stat: "list[Stat]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)


default_message_pool.register_message(
    "xray.app.stats.command", "QueryStatsResponse", QueryStatsResponse
)


@dataclass(eq=False, repr=False)
class Stat(betterproto2.Message):
    name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)

    value: "int" = betterproto2.field(2, betterproto2.TYPE_INT64)


default_message_pool.register_message("xray.app.stats.command", "Stat", Stat)


@dataclass(eq=False, repr=False)
class SysStatsRequest(betterproto2.Message):
    pass


default_message_pool.register_message(
    "xray.app.stats.command", "SysStatsRequest", SysStatsRequest
)


@dataclass(eq=False, repr=False)
class SysStatsResponse(betterproto2.Message):
    num_goroutine: "int" = betterproto2.field(1, betterproto2.TYPE_UINT32)

    num_gc: "int" = betterproto2.field(2, betterproto2.TYPE_UINT32)

    alloc: "int" = betterproto2.field(3, betterproto2.TYPE_UINT64)

    total_alloc: "int" = betterproto2.field(4, betterproto2.TYPE_UINT64)

    sys: "int" = betterproto2.field(5, betterproto2.TYPE_UINT64)

    mallocs: "int" = betterproto2.field(6, betterproto2.TYPE_UINT64)

    frees: "int" = betterproto2.field(7, betterproto2.TYPE_UINT64)

    live_objects: "int" = betterproto2.field(8, betterproto2.TYPE_UINT64)

    pause_total_ns: "int" = betterproto2.field(9, betterproto2.TYPE_UINT64)

    uptime: "int" = betterproto2.field(10, betterproto2.TYPE_UINT32)


default_message_pool.register_message(
    "xray.app.stats.command", "SysStatsResponse", SysStatsResponse
)


class StatsServiceStub(betterproto2.ServiceStub):
    async def get_stats(
        self,
        message: "GetStatsRequest",
        *,
        timeout: "float | None" = None,
        deadline: "Deadline | None" = None,
        metadata: "MetadataLike | None" = None,
    ) -> "GetStatsResponse":
        return await self._unary_unary(
            "/xray.app.stats.command.StatsService/GetStats",
            message,
            GetStatsResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_stats_online(
        self,
        message: "GetStatsRequest",
        *,
        timeout: "float | None" = None,
        deadline: "Deadline | None" = None,
        metadata: "MetadataLike | None" = None,
    ) -> "GetStatsResponse":
        return await self._unary_unary(
            "/xray.app.stats.command.StatsService/GetStatsOnline",
            message,
            GetStatsResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def query_stats(
        self,
        message: "QueryStatsRequest",
        *,
        timeout: "float | None" = None,
        deadline: "Deadline | None" = None,
        metadata: "MetadataLike | None" = None,
    ) -> "QueryStatsResponse":
        return await self._unary_unary(
            "/xray.app.stats.command.StatsService/QueryStats",
            message,
            QueryStatsResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_sys_stats(
        self,
        message: "SysStatsRequest | None" = None,
        *,
        timeout: "float | None" = None,
        deadline: "Deadline | None" = None,
        metadata: "MetadataLike | None" = None,
    ) -> "SysStatsResponse":
        if message is None:
            message = SysStatsRequest()

        return await self._unary_unary(
            "/xray.app.stats.command.StatsService/GetSysStats",
            message,
            SysStatsResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    async def get_stats_online_ip_list(
        self,
        message: "GetStatsRequest",
        *,
        timeout: "float | None" = None,
        deadline: "Deadline | None" = None,
        metadata: "MetadataLike | None" = None,
    ) -> "GetStatsOnlineIpListResponse":
        return await self._unary_unary(
            "/xray.app.stats.command.StatsService/GetStatsOnlineIpList",
            message,
            GetStatsOnlineIpListResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class StatsServiceBase(ServiceBase):
    async def get_stats(self, message: "GetStatsRequest") -> "GetStatsResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_stats_online(self, message: "GetStatsRequest") -> "GetStatsResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def query_stats(self, message: "QueryStatsRequest") -> "QueryStatsResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_sys_stats(self, message: "SysStatsRequest") -> "SysStatsResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def get_stats_online_ip_list(
        self, message: "GetStatsRequest"
    ) -> "GetStatsOnlineIpListResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_get_stats(
        self, stream: "grpclib.server.Stream[GetStatsRequest, GetStatsResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_stats(request)
        await stream.send_message(response)

    async def __rpc_get_stats_online(
        self, stream: "grpclib.server.Stream[GetStatsRequest, GetStatsResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_stats_online(request)
        await stream.send_message(response)

    async def __rpc_query_stats(
        self, stream: "grpclib.server.Stream[QueryStatsRequest, QueryStatsResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.query_stats(request)
        await stream.send_message(response)

    async def __rpc_get_sys_stats(
        self, stream: "grpclib.server.Stream[SysStatsRequest, SysStatsResponse]"
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_sys_stats(request)
        await stream.send_message(response)

    async def __rpc_get_stats_online_ip_list(
        self,
        stream: "grpclib.server.Stream[GetStatsRequest, GetStatsOnlineIpListResponse]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.get_stats_online_ip_list(request)
        await stream.send_message(response)

    def __mapping__(self) -> "dict[str, grpclib.const.Handler]":
        return {
            "/xray.app.stats.command.StatsService/GetStats": grpclib.const.Handler(
                self.__rpc_get_stats,
                grpclib.const.Cardinality.UNARY_UNARY,
                GetStatsRequest,
                GetStatsResponse,
            ),
            "/xray.app.stats.command.StatsService/GetStatsOnline": grpclib.const.Handler(
                self.__rpc_get_stats_online,
                grpclib.const.Cardinality.UNARY_UNARY,
                GetStatsRequest,
                GetStatsResponse,
            ),
            "/xray.app.stats.command.StatsService/QueryStats": grpclib.const.Handler(
                self.__rpc_query_stats,
                grpclib.const.Cardinality.UNARY_UNARY,
                QueryStatsRequest,
                QueryStatsResponse,
            ),
            "/xray.app.stats.command.StatsService/GetSysStats": grpclib.const.Handler(
                self.__rpc_get_sys_stats,
                grpclib.const.Cardinality.UNARY_UNARY,
                SysStatsRequest,
                SysStatsResponse,
            ),
            "/xray.app.stats.command.StatsService/GetStatsOnlineIpList": grpclib.const.Handler(
                self.__rpc_get_stats_online_ip_list,
                grpclib.const.Cardinality.UNARY_UNARY,
                GetStatsRequest,
                GetStatsOnlineIpListResponse,
            ),
        }
