from __future__ import annotations

"""Briefs resource — generate decision briefs."""

from typing import Any

from nexure.models import DecisionBrief
from nexure.resources._base import BaseResource


class BriefsResource(BaseResource):
    """nx.briefs — generate decision briefs."""

    def generate(
        self,
        *,
        package_id: str | None = None,
        decision_type: str | None = None,
        evidence: dict[str, Any] | None = None,
        policy_context: dict[str, Any] | None = None,
        model_output: dict[str, Any] | None = None,
        include_comparables: bool = False,
    ) -> DecisionBrief:
        """Generate a decision brief.

        Either provide (decision_type + evidence) for inline generation,
        or package_id to generate from an existing package.

        Args:
            package_id: Existing package ID.
            decision_type: Template ID (e.g. "credit_underwriting").
            evidence: Domain-specific evidence dict.
            policy_context: Policy rules that applied.
            model_output: AI model recommendation.
            include_comparables: Whether to include comparables analysis.

        Returns:
            DecisionBrief with synthesis, flags, and confidence.
        """
        payload: dict[str, Any] = {
            "include_comparables": include_comparables,
        }
        if package_id is not None:
            payload["package_id"] = package_id
        if decision_type is not None:
            payload["decision_type"] = decision_type
        if evidence is not None:
            payload["evidence"] = evidence
        if policy_context is not None:
            payload["policy_context"] = policy_context
        if model_output is not None:
            payload["model_output"] = model_output

        data = self._post("/briefs/generate", json=payload)
        return DecisionBrief(**data)

    def get(self, brief_id: str) -> DecisionBrief:
        """Get a previously generated brief by ID."""
        data = self._get(f"/briefs/{brief_id}")
        return DecisionBrief(**data)
