"""Bridge to the PlannerAgent, VOI, and cost forecast systems.

Reuses:
    - ``src.agents.planner_agent.PlannerAgent``
    - ``src.agents.voi.compute_voi()``
    - ``src.agents.cost_forecast.forecast()``
    - ``src.agents.bandit.ThompsonSamplingBandit``
    - ``src.agents.rollout.monte_carlo_rollout()``
"""

from __future__ import annotations

from typing import Any, Dict, List, Optional

from databridge_core.sdk.core.context import SDKContext
from databridge_core.sdk.core.exceptions import NotImplementedStubError


class PlannerBridge:
    """Bridge between SDK and the DataBridge planner/decision-making stack.

    Provides access to:
        - Workflow planning via ``PlannerAgent``
        - Value of Information analysis
        - Cost forecasting and budget optimization
        - Thompson Sampling strategy selection
        - Monte Carlo rollout simulation

    Reuses:
        - ``src.agents.planner_agent.PlannerAgent``
        - ``src.agents.voi.compute_voi()``
        - ``src.agents.cost_forecast.forecast(), compare_strategies()``
        - ``src.agents.bandit.ThompsonSamplingBandit``
        - ``src.agents.rollout.monte_carlo_rollout()``
    """

    def __init__(self, ctx: SDKContext):
        self._ctx = ctx

    def plan(self, user_request: str) -> Dict[str, Any]:
        """Create a workflow plan using PlannerAgent.

        Reuse: ``src.agents.planner_agent.PlannerAgent.plan_workflow(user_request)``
        """
        raise NotImplementedStubError(
            "PlannerBridge",
            "plan",
            "src.agents.planner_agent.PlannerAgent.plan_workflow(user_request)",
        )

    def compute_voi(
        self, decision_state: Dict[str, Any]
    ) -> Dict[str, Any]:
        """Compute Value of Information for a decision.

        Reuse: ``src.agents.voi.compute_voi(PlannerDecisionState(**decision_state))``
        """
        raise NotImplementedStubError(
            "PlannerBridge",
            "compute_voi",
            "src.agents.voi.compute_voi(PlannerDecisionState)",
        )

    def forecast_cost(
        self, plan: Dict[str, Any], budget: Optional[float] = None
    ) -> Dict[str, Any]:
        """Forecast cost of a workflow plan.

        Reuse: ``src.agents.cost_forecast.forecast(plan)``
               ``src.agents.cost_forecast.apply_budget(report, budget)``
        """
        raise NotImplementedStubError(
            "PlannerBridge",
            "forecast_cost",
            "src.agents.cost_forecast.forecast(plan) + apply_budget(report, budget)",
        )

    def select_strategy(
        self, strategies: List[str], context: Optional[Dict[str, Any]] = None
    ) -> str:
        """Select optimal strategy using Thompson Sampling.

        Reuse: ``src.agents.bandit.ThompsonSamplingBandit.select(strategies)``
        """
        raise NotImplementedStubError(
            "PlannerBridge",
            "select_strategy",
            "src.agents.bandit.ThompsonSamplingBandit.select(strategies)",
        )

    def simulate_rollout(
        self,
        steps: List[Dict[str, Any]],
        num_simulations: int = 100,
    ) -> Dict[str, Any]:
        """Run Monte Carlo rollout simulation on a plan.

        Reuse: ``src.agents.rollout.monte_carlo_rollout(steps, n=num_simulations)``
        """
        raise NotImplementedStubError(
            "PlannerBridge",
            "simulate_rollout",
            "src.agents.rollout.monte_carlo_rollout(steps, n=num_simulations)",
        )
