from pydantic import BaseModel, Field, field_validator


class RouteDecision(BaseModel):
    domain_id: str = "default"
    process_id: str = "general"
    confidence: float = 0.0
    reason: str = ""
    use_previous: bool = False
    decision_type: str = "start"
    explicit_switch: bool = False

    @field_validator("confidence")
    @classmethod
    def clamp_confidence(cls, value: float) -> float:
        return max(0.0, min(1.0, float(value)))


class RouteResolution(BaseModel):
    domain_id: str
    process_id: str
    confidence: float
    reason: str
    fallback_used: bool = False
    decision_type: str = "start"
    explicit_switch: bool = False


class RouterContext(BaseModel):
    last_routing: dict[str, str] | None = None
    message_history: list[dict[str, str]] = Field(default_factory=list)
    active_intent: dict[str, str] | None = None
    dialog_started: bool = False
    turn_index: int = 0
