//! Constructor for error check results

use chrono::Utc;

use crate::types::check_result::CheckResult;
use crate::types::check_status::CheckStatus;

impl CheckResult {
    /// Creates a CheckResult for a failed check
    ///
    /// # Arguments
    ///
    /// * `domain` - The domain name (without TLD)
    /// * `tld` - The top-level domain
    /// * `error_message` - Description of the error
    ///
    /// # Returns
    ///
    /// Returns a `CheckResult` with status `Error` and current timestamp.
    ///
    /// # Examples
    ///
    /// ```
    /// use lazydomain::types::CheckResult;
    ///
    /// let result = CheckResult::error("example", "com", "Network timeout");
    /// assert_eq!(result.error_message, Some("Network timeout".to_string()));
    /// ```
    pub fn error(
        domain: impl Into<String>,
        tld: impl Into<String>,
        error_message: impl Into<String>,
    ) -> Self {
        CheckResult {
            domain: domain.into(),
            tld: tld.into(),
            status: CheckStatus::Error,
            registrar: None,
            expiry_date: None,
            error_message: Some(error_message.into()),
            checked_at: Utc::now(),
        }
    }
}

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

    #[test]
    fn test_creates_error_result() {
        let result = CheckResult::error("example", "com", "Network timeout");
        assert_eq!(result.domain, "example");
        assert_eq!(result.status, CheckStatus::Error);
        assert_eq!(result.error_message, Some("Network timeout".to_string()));
    }
}
