//! Constructor for available domain results

use chrono::Utc;

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

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

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

    #[test]
    fn test_creates_available_result() {
        let result = CheckResult::available("example", "com");
        assert_eq!(result.domain, "example");
        assert_eq!(result.tld, "com");
        assert_eq!(result.status, CheckStatus::Available);
        assert!(result.registrar.is_none());
        assert!(result.error_message.is_none());
    }
}
