# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: onos/a1t/a1/policy.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import AsyncIterable, AsyncIterator, Dict, Iterable, Union

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


@dataclass(eq=False, repr=False)
class PolicyType(betterproto.Message):
    id: str = betterproto.string_field(1)
    name: str = betterproto.string_field(2)
    version: str = betterproto.string_field(3)


@dataclass(eq=False, repr=False)
class Request(betterproto.Message):
    header: "__a1__.Header" = betterproto.message_field(1)
    policy_type: "PolicyType" = betterproto.message_field(2)
    message: "__a1__.RequestMessage" = betterproto.message_field(3)


@dataclass(eq=False, repr=False)
class Result(betterproto.Message):
    header: "__a1__.Header" = betterproto.message_field(1)
    policy_type: "PolicyType" = betterproto.message_field(2)
    message: "__a1__.ResultMessage" = betterproto.message_field(3)


@dataclass(eq=False, repr=False)
class Status(betterproto.Message):
    header: "__a1__.Header" = betterproto.message_field(1)
    policy_type: "PolicyType" = betterproto.message_field(2)
    message: "__a1__.StatusMessage" = betterproto.message_field(3)


@dataclass(eq=False, repr=False)
class Ack(betterproto.Message):
    header: "__a1__.Header" = betterproto.message_field(1)
    policy_type: "PolicyType" = betterproto.message_field(2)
    message: "__a1__.AckMessage" = betterproto.message_field(3)


class PolicyServiceStub(betterproto.ServiceStub):
    async def policy_setup(
        self,
        *,
        header: "__a1__.Header" = None,
        policy_type: "PolicyType" = None,
        message: "__a1__.RequestMessage" = None,
    ) -> "Result":

        request = Request()
        if header is not None:
            request.header = header
        if policy_type is not None:
            request.policy_type = policy_type
        if message is not None:
            request.message = message

        return await self._unary_unary(
            "/onos.a1t.a1.policy.PolicyService/PolicySetup", request, Result
        )

    async def policy_update(
        self,
        *,
        header: "__a1__.Header" = None,
        policy_type: "PolicyType" = None,
        message: "__a1__.RequestMessage" = None,
    ) -> "Result":

        request = Request()
        if header is not None:
            request.header = header
        if policy_type is not None:
            request.policy_type = policy_type
        if message is not None:
            request.message = message

        return await self._unary_unary(
            "/onos.a1t.a1.policy.PolicyService/PolicyUpdate", request, Result
        )

    async def policy_delete(
        self,
        *,
        header: "__a1__.Header" = None,
        policy_type: "PolicyType" = None,
        message: "__a1__.RequestMessage" = None,
    ) -> "Result":

        request = Request()
        if header is not None:
            request.header = header
        if policy_type is not None:
            request.policy_type = policy_type
        if message is not None:
            request.message = message

        return await self._unary_unary(
            "/onos.a1t.a1.policy.PolicyService/PolicyDelete", request, Result
        )

    async def policy_query(
        self,
        *,
        header: "__a1__.Header" = None,
        policy_type: "PolicyType" = None,
        message: "__a1__.RequestMessage" = None,
    ) -> "Result":

        request = Request()
        if header is not None:
            request.header = header
        if policy_type is not None:
            request.policy_type = policy_type
        if message is not None:
            request.message = message

        return await self._unary_unary(
            "/onos.a1t.a1.policy.PolicyService/PolicyQuery", request, Result
        )

    async def policy_status(
        self, request_iterator: Union[AsyncIterable["Ack"], Iterable["Ack"]]
    ) -> AsyncIterator["Status"]:

        async for response in self._stream_stream(
            "/onos.a1t.a1.policy.PolicyService/PolicyStatus",
            request_iterator,
            Ack,
            Status,
        ):
            yield response


class PolicyServiceBase(ServiceBase):
    async def policy_setup(
        self,
        header: "__a1__.Header",
        policy_type: "PolicyType",
        message: "__a1__.RequestMessage",
    ) -> "Result":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def policy_update(
        self,
        header: "__a1__.Header",
        policy_type: "PolicyType",
        message: "__a1__.RequestMessage",
    ) -> "Result":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def policy_delete(
        self,
        header: "__a1__.Header",
        policy_type: "PolicyType",
        message: "__a1__.RequestMessage",
    ) -> "Result":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def policy_query(
        self,
        header: "__a1__.Header",
        policy_type: "PolicyType",
        message: "__a1__.RequestMessage",
    ) -> "Result":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def policy_status(
        self, request_iterator: AsyncIterator["Ack"]
    ) -> AsyncIterator["Status"]:
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

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

        request_kwargs = {
            "header": request.header,
            "policy_type": request.policy_type,
            "message": request.message,
        }

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

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

        request_kwargs = {
            "header": request.header,
            "policy_type": request.policy_type,
            "message": request.message,
        }

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

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

        request_kwargs = {
            "header": request.header,
            "policy_type": request.policy_type,
            "message": request.message,
        }

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

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

        request_kwargs = {
            "header": request.header,
            "policy_type": request.policy_type,
            "message": request.message,
        }

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

    async def __rpc_policy_status(self, stream: grpclib.server.Stream) -> None:
        request_kwargs = {"request_iterator": stream.__aiter__()}

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

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/onos.a1t.a1.policy.PolicyService/PolicySetup": grpclib.const.Handler(
                self.__rpc_policy_setup,
                grpclib.const.Cardinality.UNARY_UNARY,
                Request,
                Result,
            ),
            "/onos.a1t.a1.policy.PolicyService/PolicyUpdate": grpclib.const.Handler(
                self.__rpc_policy_update,
                grpclib.const.Cardinality.UNARY_UNARY,
                Request,
                Result,
            ),
            "/onos.a1t.a1.policy.PolicyService/PolicyDelete": grpclib.const.Handler(
                self.__rpc_policy_delete,
                grpclib.const.Cardinality.UNARY_UNARY,
                Request,
                Result,
            ),
            "/onos.a1t.a1.policy.PolicyService/PolicyQuery": grpclib.const.Handler(
                self.__rpc_policy_query,
                grpclib.const.Cardinality.UNARY_UNARY,
                Request,
                Result,
            ),
            "/onos.a1t.a1.policy.PolicyService/PolicyStatus": grpclib.const.Handler(
                self.__rpc_policy_status,
                grpclib.const.Cardinality.STREAM_STREAM,
                Ack,
                Status,
            ),
        }


from ... import a1 as __a1__
