//! Error types for LLM operations

use thiserror::Error;

/// LLM operation errors
#[derive(Debug, Error)]
pub enum LlmError {
    #[error("API error: {0}")]
    ApiError(String),

    #[error("Configuration error: {0}")]
    ConfigError(String),

    #[error("Network error: {0}")]
    NetworkError(#[from] reqwest::Error),

    #[error("JSON error: {0}")]
    JsonError(#[from] serde_json::Error),

    #[error("Provider not available: {0}")]
    ProviderUnavailable(String),

    #[error("Rate limit exceeded: {0}")]
    RateLimit(String),

    #[error("Invalid message format: {0}")]
    InvalidMessage(String),

    #[error("Stream error: {0}")]
    StreamError(String),

    #[error("Timeout: {0}")]
    Timeout(String),

    #[error("{0}")]
    Other(String),
}

/// Result type for LLM operations
pub type Result<T> = std::result::Result<T, LlmError>;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_error_display() {
        let err = LlmError::ConfigError("missing API key".to_string());
        assert_eq!(err.to_string(), "Configuration error: missing API key");
    }

    #[test]
    fn test_error_creation() {
        let err: Result<()> = Err(LlmError::ProviderUnavailable("OpenAI".into()));
        assert!(err.is_err());
    }
}
