from __future__ import annotations


class OuteAIError(Exception):
    """Base SDK error."""


class OuteAIAPIError(OuteAIError):
    """Raised when the OuteAI API returns a non-success response."""

    def __init__(
        self,
        message: str,
        *,
        status_code: int | None = None,
        code: str | None = None,
        payload: dict | None = None,
    ) -> None:
        super().__init__(message)
        self.message = message
        self.status_code = status_code
        self.code = code
        self.payload = payload or {}

    def __str__(self) -> str:
        details: list[str] = []
        if self.status_code is not None:
            details.append(f"status={self.status_code}")
        if self.code:
            details.append(f"code={self.code}")

        if not details:
            return self.message

        return f"{self.message} ({', '.join(details)})"
