"""
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
"""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Generic, Optional, TypeVar

from botbuilder.core import TurnContext

from ...state import TurnState
from ...user_agent import _UserAgent
from ..planners.plan import Plan

StateT = TypeVar("StateT", bound=TurnState)


class Moderator(ABC, _UserAgent, Generic[StateT]):
    """
    A moderator is responsible for reviewing and approving AI prompts and plans.
    """

    @abstractmethod
    async def review_input(self, context: TurnContext, state: StateT) -> Optional[Plan]:
        """
        Reviews an incoming utterance and generated prompt before it's sent to the planner.

        Args:
            context (TurnContext): the current turn of conversation.
            state (TurnState): the current turn state.

        Returns:
            Optional[Plan]: if approved then returns None, otherwise returns a new plan
                to redirect.
        """

    @abstractmethod
    async def review_output(self, context: TurnContext, state: StateT, plan: Plan) -> Plan:
        """
        Reviews a plan generated by the planner before its executed.

        Args:
            context (TurnContext): the current turn of conversation.
            state (TurnState): the current turn state.
            plan (Plan): plan generated by the planner.

        Returns:
            Plan: the plan to execute. Either the current plan passed in for review
                or a new plan.
        """
