from __future__ import annotations

from dataclasses import asdict, dataclass
from enum import Enum


@dataclass(slots=True)
class SlotValidationError:
    """Describe one slot-level validation problem."""

    slot_name: str
    code: str
    message: str

    def to_dict(self) -> dict[str, object]:
        """Serialize the slot validation error into the public response shape."""
        return asdict(self)


@dataclass(slots=True)
class SlotValidationResult:
    """Represent the combined outcome of slot validation."""

    passed: bool
    slot_errors: list[SlotValidationError]


class GuardrailDecision(str, Enum):
    """Unified guardrail decision semantics."""

    ALLOW = "allow"
    BLOCK = "block"
    MASK = "mask"
    REVIEW = "review"


@dataclass(slots=True)
class GuardrailRequest:
    """Normalized guardrail input request."""

    text: str
    metadata: dict[str, object] | None = None
    policy_id: str | None = None


@dataclass(slots=True)
class GuardrailResult:
    """Represent the normalized result returned by a safety guardrail."""

    passed: bool
    decision: GuardrailDecision = GuardrailDecision.ALLOW
    category: str | None = None
    reason: str | None = None
    raw_response: dict[str, object] | None = None
    provider: str | None = None
    policy_id: str | None = None
    error_code: str | None = None
    error_message: str | None = None
