"""SentimentScanner for meshulash-guard SDK.

Detects negative or hostile sentiment in user input using VADER compound
score analysis on the server side. English-only — Hebrew input returns
untriggered. The scanner is a pure config serializer: no detection logic
runs in the SDK.
"""

from __future__ import annotations

from ..enums import Action
from .base import BaseScanner


class SentimentScanner(BaseScanner):
    """Scanner for negative/hostile sentiment detection.

    Uses VADER compound score (server-side) to detect hostility or very
    negative affect. VADER compound scores range from -1.0 (most negative)
    to +1.0 (most positive); the threshold marks the *upper* bound for
    triggering — i.e. scores *below* the threshold are flagged.

    English-only: Hebrew or non-English input is not scored by VADER and
    will be returned as untriggered by the server.

    Args:
        threshold: VADER compound score upper bound for triggering.
            Must be in [-1.0, 0.0]. Defaults to -0.5.
        action: Action to take when negative sentiment is detected.
            Defaults to BLOCK.

    Raises:
        ValueError: If threshold is outside the valid range [-1.0, 0.0].
    """

    def __init__(
        self,
        threshold: float = -0.5,
        action: Action = Action.BLOCK,
    ) -> None:
        if not (-1.0 <= threshold <= 0.0):
            raise ValueError(
                f"SentimentScanner threshold must be in [-1.0, 0.0], got {threshold!r}. "
                "VADER compound scores for negative sentiment are non-positive."
            )
        self._threshold = threshold
        self._action = action

    def to_guardline_spec(self) -> dict:
        """Return a flat guardline spec dict for this scanner configuration."""
        return {
            "name": "SentimentScanner",
            "action": str(self._action),
            "threshold": self._threshold,
            "level": 3,
        }
