

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: blickfeld/push/services/destination.proto, blickfeld/push/services/health.proto, blickfeld/push/services/push.proto
# plugin: python-betterproto
import asyncio
from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    AsyncIterator,
    Dict,
    Iterator,
    Optional,
)

import blickfeld_qb2.betterproto as betterproto
import blickfeld_qb2.betterproto.lib.google.protobuf as betterproto_lib_google_protobuf
import grpclib
from blickfeld_qb2.betterproto.grpc.grpclib_server import ServiceBase

from .. import (
    config as _config__,
    data as _data__,
)


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


@dataclass(eq=False, repr=False)
class DestinationValidateRequest(betterproto.Message):
    """request to validate a configured destination"""

    destination: "_config__.Destination" = betterproto.message_field(1)
    """the current (possibly incomplete) configuration entered"""


@dataclass(eq=False, repr=False)
class HealthGetResponse(betterproto.Message):
    """request get the health of the configured publisher"""

    health: "_data__.Health" = betterproto.message_field(2)
    """health of push configurations"""


@dataclass(eq=False, repr=False)
class HealthWatchResponse(betterproto.Message):
    """request watch the health of the configured publisher"""

    health: "_data__.Health" = betterproto.message_field(2)
    """health of push configurations"""


@dataclass(eq=False, repr=False)
class PushStoreRequest(betterproto.Message):
    """request to add a push configuration"""

    uuid: str = betterproto.string_field(1)
    """the uuid of the configuration (has to be generated on client side!)"""

    push_config: "_config__.Push" = betterproto.message_field(2)
    """push configuration to add"""


@dataclass(eq=False, repr=False)
class PushDeleteRequest(betterproto.Message):
    """request to delete a push configuration"""

    uuid: str = betterproto.string_field(1)
    """configuration uuid to delete"""


@dataclass(eq=False, repr=False)
class PushListResponse(betterproto.Message):
    """request to list all configured push configurations"""

    push_configs: Dict[str, "_config__.Push"] = betterproto.map_field(
        1, betterproto.TYPE_STRING, betterproto.TYPE_MESSAGE
    )
    """current snapshot of configured push configurations"""


@dataclass(eq=False, repr=False)
class PushWatchResponse(betterproto.Message):
    """request to watch all configured push configurations"""

    push_configs: Dict[str, "_config__.Push"] = betterproto.map_field(
        1, betterproto.TYPE_STRING, betterproto.TYPE_MESSAGE
    )
    """current snapshot of configured push configurations"""


@dataclass(eq=False, repr=False)
class PushEnableRequest(betterproto.Message):
    """request to enable the push configuration with the given uuid"""

    uuid: str = betterproto.string_field(1)
    """configuration uuid to enable"""


@dataclass(eq=False, repr=False)
class PushDisableRequest(betterproto.Message):
    """request to disable the push configuration with the given uuid"""

    uuid: str = betterproto.string_field(1)
    """configuration uuid to disable"""


class Destination(betterproto.ServiceStub):
    """An gRPC service to configure multiple push settings"""

    async def async_validate(
        self,
        *,
        destination: "_config__.Destination" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Setting validation"""

        request = DestinationValidateRequest()
        if destination is not None:
            request.destination = destination

        return await self._unary_unary(
            "/blickfeld.push.services.Destination/Validate",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def validate(
        self,
        *,
        destination: "_config__.Destination" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Setting validation"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_validate(
                destination=destination,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )


class Health(betterproto.ServiceStub):
    """An gRPC service to request the status of push configurations"""

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "HealthGetResponse":
        """Get Status for all configured push configurations"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.push.services.Health/Get",
            request,
            HealthGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "HealthGetResponse":
        """Get Status for all configured push configurations"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_get(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_watch(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> AsyncIterator["HealthWatchResponse"]:
        """Watch status changes for configured push configurations"""

        request = betterproto_lib_google_protobuf.Empty()

        async for response in self._unary_stream(
            "/blickfeld.push.services.Health/Watch",
            request,
            HealthWatchResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    def watch(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> Iterator["HealthWatchResponse"]:
        """Watch status changes for configured push configurations"""

        loop = asyncio.get_event_loop()
        ait = self.async_watch(
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ).__aiter__()

        async def get_next():
            try:
                obj = await ait.__anext__()
                return False, obj
            except StopAsyncIteration:
                return True, None

        while True:
            done, obj = loop.run_until_complete(get_next())
            if done:
                break
            yield obj


class Push(betterproto.ServiceStub):
    """An gRPC service to configure multiple push settings"""

    async def async_store(
        self,
        *,
        uuid: str = "",
        push_config: "_config__.Push" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store (Add or Update a push configuration)"""

        request = PushStoreRequest()
        request.uuid = uuid
        if push_config is not None:
            request.push_config = push_config

        return await self._unary_unary(
            "/blickfeld.push.services.Push/Store",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def store(
        self,
        *,
        uuid: str = "",
        push_config: "_config__.Push" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store (Add or Update a push configuration)"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_store(
                uuid=uuid,
                push_config=push_config,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_delete(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Delete an existing push configuration"""

        request = PushDeleteRequest()
        request.uuid = uuid

        return await self._unary_unary(
            "/blickfeld.push.services.Push/Delete",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def delete(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Delete an existing push configuration"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_delete(
                uuid=uuid,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_list(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "PushListResponse":
        """List configured push configuration"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.push.services.Push/List",
            request,
            PushListResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def list(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "PushListResponse":
        """List configured push configuration"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_list(
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_watch(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> AsyncIterator["PushWatchResponse"]:
        """Watch list of configured push configuration"""

        request = betterproto_lib_google_protobuf.Empty()

        async for response in self._unary_stream(
            "/blickfeld.push.services.Push/Watch",
            request,
            PushWatchResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    def watch(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> Iterator["PushWatchResponse"]:
        """Watch list of configured push configuration"""

        loop = asyncio.get_event_loop()
        ait = self.async_watch(
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ).__aiter__()

        async def get_next():
            try:
                obj = await ait.__anext__()
                return False, obj
            except StopAsyncIteration:
                return True, None

        while True:
            done, obj = loop.run_until_complete(get_next())
            if done:
                break
            yield obj

    async def async_enable(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Enable a configured Push"""

        request = PushEnableRequest()
        request.uuid = uuid

        return await self._unary_unary(
            "/blickfeld.push.services.Push/Enable",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def enable(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Enable a configured Push"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_enable(
                uuid=uuid,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_disable(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Disable a configured Push"""

        request = PushDisableRequest()
        request.uuid = uuid

        return await self._unary_unary(
            "/blickfeld.push.services.Push/Disable",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def disable(
        self,
        *,
        uuid: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Disable a configured Push"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_disable(
                uuid=uuid,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )
