// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

use thiserror::Error;

/// Mirrors `targets::typescript`'s `McpifyError` hierarchy (`errors.ts`):
/// one variant per error family, each carrying the literal `code()` string
/// callers match on instead of downcasting.
#[derive(Debug, Error)]
pub enum McpifyError {
    #[error("{0}")]
    Configuration(String),

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

    #[error("{message}")]
    Validation {
        message: String,
        details: Option<serde_json::Value>,
    },

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

    #[error("circuit breaker is open")]
    CircuitBreakerOpen,

    #[error("rate limit exceeded")]
    RateLimitExceeded,
}

impl McpifyError {
    pub fn code(&self) -> &'static str {
        match self {
            Self::Configuration(_) => "CONFIGURATION_ERROR",
            Self::Authentication(_) => "AUTHENTICATION_ERROR",
            Self::Validation { .. } => "VALIDATION_ERROR",
            Self::NotFound(_) => "NOT_FOUND",
            Self::CircuitBreakerOpen => "CIRCUIT_BREAKER_OPEN",
            Self::RateLimitExceeded => "RATE_LIMIT_EXCEEDED",
        }
    }
}

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

    #[test]
    fn every_variant_reports_its_error_code() {
        assert_eq!(
            McpifyError::Configuration("x".into()).code(),
            "CONFIGURATION_ERROR"
        );
        assert_eq!(
            McpifyError::Authentication("x".into()).code(),
            "AUTHENTICATION_ERROR"
        );
        assert_eq!(
            McpifyError::Validation {
                message: "x".into(),
                details: None
            }
            .code(),
            "VALIDATION_ERROR"
        );
        assert_eq!(McpifyError::NotFound("x".into()).code(), "NOT_FOUND");
        assert_eq!(
            McpifyError::CircuitBreakerOpen.code(),
            "CIRCUIT_BREAKER_OPEN"
        );
        assert_eq!(McpifyError::RateLimitExceeded.code(), "RATE_LIMIT_EXCEEDED");
    }
}
