from typing import Literal
from pydantic import BaseModel, ConfigDict, Field


class StrictModel(BaseModel):
    """Base class that rejects fields not declared in the schema."""
    model_config = ConfigDict(extra="forbid")


class SentimentResult(StrictModel):
    sentiment: Literal["positive", "neutral", "negative"]
    frustration_score: int = Field(ge=0, le=10)
    reason: str


class IssueResult(StrictModel):
    issue_type: Literal[
        "bug",
        "feature_request",
        "billing",
        "usability",
        "performance",
        "security",
        "support",
        "general_feedback",
    ]
    issue: str
    feature_request: str | None


class RiskResult(StrictModel):
    urgency_score: int = Field(ge=0, le=10)
    churn_risk_score: int = Field(ge=0, le=10)
    churn_signal: str


class RoutingResult(StrictModel):
    department: Literal[
        "Engineering",
        "Product",
        "Billing",
        "Support",
        "Security",
        "Customer Success",
    ]
    reason: str


class FinalAnalysis(StrictModel):
    customer_id: str
    feedback: str
    sentiment: SentimentResult
    issue: IssueResult
    risk: RiskResult
    routing: RoutingResult
    priority_score: float = Field(ge=0, le=100)
    priority_level: Literal["LOW", "MEDIUM", "HIGH", "CRITICAL"]
