# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: blickfeld/flow/services/credentials.proto, blickfeld/flow/services/flow.proto, blickfeld/flow/services/settings.proto
# plugin: python-betterproto
import asyncio
from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    Dict,
    List,
    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__


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 FlowGetRequest(betterproto.Message):
    """Flow get request"""

    id: str = betterproto.string_field(1)
    """Flow id"""

    as_node_red_json: bool = betterproto.bool_field(2)
    """
    If true, the request returns the NodeRed JSON format which can be directly
    imported.
    """


@dataclass(eq=False, repr=False)
class FlowGetResponse(betterproto.Message):
    """Flow get response"""

    flow: "_config__.Flow" = betterproto.message_field(1, group="kind")
    """Blickfeld Flow config with well-defined high-level attributes"""

    node_red_json: "_config__.NodeRedJson" = betterproto.message_field(2, group="kind")
    """NodeRed JSON format which can be directly imported"""


@dataclass(eq=False, repr=False)
class FlowListResponse(betterproto.Message):
    """Flow list response"""

    ids: List[str] = betterproto.string_field(1)
    """List of Blickfeld Flow identifiers."""


@dataclass(eq=False, repr=False)
class FlowStoreRequest(betterproto.Message):
    """Flow store request"""

    id: str = betterproto.string_field(1)
    """
    ID of the flow NOTE: For node_red_json, this has to match the ID in the
    NodeRED JSON format.
    """

    flow: "_config__.Flow" = betterproto.message_field(2, group="kind")
    """Blickfeld Flow config with well-defined high-level attributes"""

    node_red_json: "_config__.NodeRedJson" = betterproto.message_field(3, group="kind")
    """
    NodeRed JSON format which can be directly exported from NodeRED Admin UI
    """


@dataclass(eq=False, repr=False)
class FlowDeleteRequest(betterproto.Message):
    """Flow delete request"""

    id: str = betterproto.string_field(1)
    """Id of Blickfeld Flow"""


@dataclass(eq=False, repr=False)
class FlowStoreGlobalNodesRequest(betterproto.Message):
    """Flow store global nodes request"""

    node_red_json: "_config__.NodeRedJson" = betterproto.message_field(1)
    """NodeRed JSON format of all global configuration nodes"""


@dataclass(eq=False, repr=False)
class FlowGetGlobalNodesResponse(betterproto.Message):
    """Flow get global nodes response"""

    node_red_json: "_config__.NodeRedJson" = betterproto.message_field(1)
    """NodeRed JSON format of all global configuration nodes"""


@dataclass(eq=False, repr=False)
class SettingsSetRequest(betterproto.Message):
    """Settings set request"""

    settings: "betterproto_lib_google_protobuf.Struct" = betterproto.message_field(1)
    """
    Settings which should be stored Generic JSON format which is defined by
    NodeRed.
    """


@dataclass(eq=False, repr=False)
class SettingsGetResponse(betterproto.Message):
    """Settings get request"""

    settings: "betterproto_lib_google_protobuf.Struct" = betterproto.message_field(1)
    """Current settings Generic JSON format which is defined by NodeRed."""


@dataclass(eq=False, repr=False)
class CredentialsSetRequest(betterproto.Message):
    """Credentials set request"""

    credentials: "betterproto_lib_google_protobuf.Struct" = betterproto.message_field(1)
    """
    Credentials which should be stored Generic JSON format which is defined by
    NodeRed.
    """


@dataclass(eq=False, repr=False)
class CredentialsGetResponse(betterproto.Message):
    """Credentails get response"""

    credentials: "betterproto_lib_google_protobuf.Struct" = betterproto.message_field(1)
    """Current credentials Generic JSON format which is defined by NodeRed."""


class Flow(betterproto.ServiceStub):
    """
    Service to store and control Blickfeld flows. It is used to implement the
    custom storage API: https://nodered.org/docs/api/storage/
    """

    async def async_get(
        self,
        *,
        id: str = "",
        as_node_red_json: bool = False,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "FlowGetResponse":
        """Get a flow by id"""

        request = FlowGetRequest()
        request.id = id
        request.as_node_red_json = as_node_red_json

        return await self._unary_unary(
            "/blickfeld.flow.services.Flow/Get",
            request,
            FlowGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get(
        self,
        *,
        id: str = "",
        as_node_red_json: bool = False,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "FlowGetResponse":
        """Get a flow by id"""

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

    async def async_list(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "FlowListResponse":
        """Return list of flow ids"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.flow.services.Flow/List",
            request,
            FlowListResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def list(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "FlowListResponse":
        """Return list of flow ids"""

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

    async def async_store(
        self,
        *,
        id: str = "",
        flow: "_config__.Flow" = None,
        node_red_json: "_config__.NodeRedJson" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store flow"""

        request = FlowStoreRequest()
        request.id = id
        if flow is not None:
            request.flow = flow
        if node_red_json is not None:
            request.node_red_json = node_red_json

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

    def store(
        self,
        *,
        id: str = "",
        flow: "_config__.Flow" = None,
        node_red_json: "_config__.NodeRedJson" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store flow"""

        loop = asyncio.get_event_loop()
        return loop.run_until_complete(
            self.async_store(
                id=id,
                flow=flow,
                node_red_json=node_red_json,
                timeout=timeout,
                deadline=deadline,
                metadata=metadata,
            )
        )

    async def async_delete(
        self,
        *,
        id: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Delete stored flow"""

        request = FlowDeleteRequest()
        request.id = id

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

    def delete(
        self,
        *,
        id: str = "",
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Delete stored flow"""

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

    async def async_store_global_nodes(
        self,
        *,
        node_red_json: "_config__.NodeRedJson" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store global nodes"""

        request = FlowStoreGlobalNodesRequest()
        if node_red_json is not None:
            request.node_red_json = node_red_json

        return await self._unary_unary(
            "/blickfeld.flow.services.Flow/StoreGlobalNodes",
            request,
            betterproto_lib_google_protobuf.Empty,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def store_global_nodes(
        self,
        *,
        node_red_json: "_config__.NodeRedJson" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """Store global nodes"""

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

    async def async_get_global_nodes(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "FlowGetGlobalNodesResponse":
        """Get global nodes"""

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.flow.services.Flow/GetGlobalNodes",
            request,
            FlowGetGlobalNodesResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get_global_nodes(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "FlowGetGlobalNodesResponse":
        """Get global nodes"""

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


class Settings(betterproto.ServiceStub):
    """
    Configuration service to store the NodeRed Settings. It is used to
    implement the custom storage API: https://nodered.org/docs/api/storage/
    """

    async def async_set(
        self,
        *,
        settings: "betterproto_lib_google_protobuf.Struct" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Set settings Used by https://nodered.org/docs/api/storage/methods/#stor
        agesavesettingssettings
        """

        request = SettingsSetRequest()
        if settings is not None:
            request.settings = settings

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

    def set(
        self,
        *,
        settings: "betterproto_lib_google_protobuf.Struct" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Set settings Used by https://nodered.org/docs/api/storage/methods/#stor
        agesavesettingssettings
        """

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

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "SettingsGetResponse":
        """
        Get settings Used by
        https://nodered.org/docs/api/storage/methods/#storagegetsettings
        """

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.flow.services.Settings/Get",
            request,
            SettingsGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "SettingsGetResponse":
        """
        Get settings Used by
        https://nodered.org/docs/api/storage/methods/#storagegetsettings
        """

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


class Credentials(betterproto.ServiceStub):
    """
    Service to store the NodeRed credentials. It is used to implement the
    custom storage API: https://nodered.org/docs/api/storage/
    """

    async def async_set(
        self,
        *,
        credentials: "betterproto_lib_google_protobuf.Struct" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Set credentials Used by https://nodered.org/docs/api/storage/methods/#s
        toragesavecredentialscredentials
        """

        request = CredentialsSetRequest()
        if credentials is not None:
            request.credentials = credentials

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

    def set(
        self,
        *,
        credentials: "betterproto_lib_google_protobuf.Struct" = None,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None
    ) -> "betterproto_lib_google_protobuf.Empty":
        """
        Set credentials Used by https://nodered.org/docs/api/storage/methods/#s
        toragesavecredentialscredentials
        """

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

    async def async_get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "CredentialsGetResponse":
        """
        Get credentials Used by
        https://nodered.org/docs/api/storage/methods/#storagegetcredentials
        """

        request = betterproto_lib_google_protobuf.Empty()

        return await self._unary_unary(
            "/blickfeld.flow.services.Credentials/Get",
            request,
            CredentialsGetResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )

    def get(
        self,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "CredentialsGetResponse":
        """
        Get credentials Used by
        https://nodered.org/docs/api/storage/methods/#storagegetcredentials
        """

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