---
to: "src/errors/{{ error | snake_case }}_error.rs"
vars:
  error: "InvalidError"
  type: "Invalid_LOWER"
---

use std::error::Error;
use std::fmt;

/// Invalid error type
#[derive(Debug, Clone)]
pub struct InvalidError {
    pub message: String,
    pub details: Option<String>,
}

impl InvalidError {
    pub fn new(message: impl Into<String>) -> Self {
        Self {
            message: message.into(),
            details: None,
        }
    }

    pub fn with_details(message: impl Into<String>, details: impl Into<String>) -> Self {
        Self {
            message: message.into(),
            details: Some(details.into()),
        }
    }
}

impl fmt::Display for InvalidError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Invalid: {}", self.message)?;
        if let Some(ref details) = self.details {
            write!(f, " ({})", details)?;
        }
        Ok(())
    }
}

impl Error for InvalidError {}
