

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: blickfeld/video/services/health.proto, blickfeld/video/services/visualization.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 HealthGetResponse(betterproto.Message):
    """Response to Health Get request"""

    health: "_data__.Health" = betterproto.message_field(1)
    """Health state"""


@dataclass(eq=False, repr=False)
class HealthWatchResponse(betterproto.Message):
    """Response to Health Watch request"""

    health: "_data__.Health" = betterproto.message_field(1)
    """Health state"""


@dataclass(eq=False, repr=False)
class VisualizationGetRequest(betterproto.Message):
    """Get Visualization Request"""

    pass


@dataclass(eq=False, repr=False)
class VisualizationGetResponse(betterproto.Message):
    """Get Visualization response"""

    configuration: "_config__.Visualization" = betterproto.message_field(1)
    """visualization configuration"""


@dataclass(eq=False, repr=False)
class VisualizationSetRequest(betterproto.Message):
    """Set Visualization request"""

    configuration: "_config__.Visualization" = betterproto.message_field(2)
    """visualization configuration"""


class Health(betterproto.ServiceStub):
    """
    The health service provides methods to monitor operational status of the
    video module
    """

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "HealthGetResponse":
        """Returns the current health status of the video module"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.video.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":
        """Returns the current health status of the video module"""

        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"]:
        """
        Continously returns the current health status of the video module
        """

        request = betterproto_lib_google_protobuf.Empty()

        async for response in self._unary_stream(
            "/blickfeld.video.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"]:
        """
        Continously returns the current health status of the video module
        """

        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 Visualization(betterproto.ServiceStub):
    """
    Service allows to change the visuals of RTSP video stream served by Qb2.
    Changes can be applicable to the elements of the observed scene frame (e.g.
    background, objects) and to extra overlay elements (e.g. logo branding,
    time, clock, background color)
    """

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> AsyncIterator["VisualizationGetResponse"]:
        """Gets named visual configuration"""

        request = VisualizationGetRequest()

        async for response in self._unary_stream(
            "/blickfeld.video.services.Visualization/Get",
            request,
            VisualizationGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        ):
            yield response

    def get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> Iterator["VisualizationGetResponse"]:
        """Gets named visual configuration"""

        loop = asyncio.get_event_loop()
        ait = self.async_get(
            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_set(
        self,
        *,
        configuration: "_config__.Visualization" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Applies visualization configuration to the video stream"""

        request = VisualizationSetRequest()
        if configuration is not None:
            request.configuration = configuration

        return await self._unary_unary(
            "/blickfeld.video.services.Visualization/Set",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def set(
        self,
        *,
        configuration: "_config__.Visualization" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Applies visualization configuration to the video stream"""

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