from __future__ import annotations

"""Packages resource — create decision packages."""

from typing import Any

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


class PackagesResource(BaseResource):
    """nx.packages — create and retrieve decision packages."""

    def create(
        self,
        *,
        decision_type: str,
        evidence: dict[str, Any],
        subject: dict[str, Any] | None = None,
        policy_context: dict[str, Any] | None = None,
        model_output: dict[str, Any] | None = None,
        source_system: str | None = None,
        source_agent: str | None = None,
        metadata: dict[str, Any] | None = None,
    ) -> DecisionPackage:
        """Create a standalone decision package."""
        payload: dict[str, Any] = {
            "decision_type": decision_type,
            "evidence": evidence,
        }
        if subject is not None:
            payload["subject"] = subject
        if policy_context is not None:
            payload["policy_context"] = policy_context
        if model_output is not None:
            payload["model_output"] = model_output
        if source_system is not None:
            payload["source_system"] = source_system
        if source_agent is not None:
            payload["source_agent"] = source_agent
        if metadata is not None:
            payload["metadata"] = metadata

        data = self._post("/packages", json=payload)
        return DecisionPackage(**data)

    def get(self, package_id: str) -> DecisionPackage:
        """Get a decision package by ID."""
        data = self._get(f"/packages/{package_id}")
        return DecisionPackage(**data)
