# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: okapi/examples/v1/examples.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import AsyncIterator, Dict, List, Optional

import betterproto
from betterproto.grpc.grpclib_server import ServiceBase
import grpclib


@dataclass(eq=False, repr=False)
class BasicMessage(betterproto.Message):
    text: str = betterproto.string_field(1)


class SecureExampleServiceStub(betterproto.ServiceStub):
    async def unary(
        self,
        *,
        iv: bytes = b"",
        aad: bytes = b"",
        ciphertext: bytes = b"",
        tag: bytes = b"",
        recipients: Optional[List["EncryptionRecipient"]] = None,
    ) -> "___pbmse_v1__.EncryptedMessage":
        recipients = recipients or []

        request = ___pbmse_v1__.EncryptedMessage()
        request.iv = iv
        request.aad = aad
        request.ciphertext = ciphertext
        request.tag = tag
        if recipients is not None:
            request.recipients = recipients

        return await self._unary_unary(
            "/okapi.examples.v1.SecureExampleService/Unary",
            request,
            ___pbmse_v1__.EncryptedMessage,
        )

    async def server_streaming(
        self,
        *,
        iv: bytes = b"",
        aad: bytes = b"",
        ciphertext: bytes = b"",
        tag: bytes = b"",
        recipients: Optional[List["EncryptionRecipient"]] = None,
    ) -> AsyncIterator["___pbmse_v1__.EncryptedMessage"]:
        recipients = recipients or []

        request = ___pbmse_v1__.EncryptedMessage()
        request.iv = iv
        request.aad = aad
        request.ciphertext = ciphertext
        request.tag = tag
        if recipients is not None:
            request.recipients = recipients

        async for response in self._unary_stream(
            "/okapi.examples.v1.SecureExampleService/ServerStreaming",
            request,
            ___pbmse_v1__.EncryptedMessage,
        ):
            yield response


class SecureExampleServiceBase(ServiceBase):
    async def unary(
        self,
        iv: bytes,
        aad: bytes,
        ciphertext: bytes,
        tag: bytes,
        recipients: Optional[List["EncryptionRecipient"]],
    ) -> "___pbmse_v1__.EncryptedMessage":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def server_streaming(
        self,
        iv: bytes,
        aad: bytes,
        ciphertext: bytes,
        tag: bytes,
        recipients: Optional[List["EncryptionRecipient"]],
    ) -> AsyncIterator["___pbmse_v1__.EncryptedMessage"]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_unary(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "iv": request.iv,
            "aad": request.aad,
            "ciphertext": request.ciphertext,
            "tag": request.tag,
            "recipients": request.recipients,
        }

        response = await self.unary(**request_kwargs)
        await stream.send_message(response)

    async def __rpc_server_streaming(self, stream: grpclib.server.Stream) -> None:
        request = await stream.recv_message()

        request_kwargs = {
            "iv": request.iv,
            "aad": request.aad,
            "ciphertext": request.ciphertext,
            "tag": request.tag,
            "recipients": request.recipients,
        }

        await self._call_rpc_handler_server_stream(
            self.server_streaming,
            stream,
            request_kwargs,
        )

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/okapi.examples.v1.SecureExampleService/Unary": grpclib.const.Handler(
                self.__rpc_unary,
                grpclib.const.Cardinality.UNARY_UNARY,
                ___pbmse_v1__.EncryptedMessage,
                ___pbmse_v1__.EncryptedMessage,
            ),
            "/okapi.examples.v1.SecureExampleService/ServerStreaming": grpclib.const.Handler(
                self.__rpc_server_streaming,
                grpclib.const.Cardinality.UNARY_STREAM,
                ___pbmse_v1__.EncryptedMessage,
                ___pbmse_v1__.EncryptedMessage,
            ),
        }


from ....pbmse import v1 as ___pbmse_v1__
