//! Constructor for taken domain results

use chrono::{DateTime, Utc};

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

impl CheckResult {
    /// Creates a CheckResult for a taken domain
    ///
    /// # Arguments
    ///
    /// * `domain` - The domain name (without TLD)
    /// * `tld` - The top-level domain
    /// * `registrar` - Optional registrar information
    /// * `expiry_date` - Optional domain expiry date
    ///
    /// # Returns
    ///
    /// Returns a `CheckResult` with status `Taken` and current timestamp.
    ///
    /// # Examples
    ///
    /// ```
    /// use lazydomain::types::CheckResult;
    ///
    /// let result = CheckResult::taken("google", "com", Some("Markmonitor Inc.".to_string()), None);
    /// assert_eq!(result.domain, "google");
    /// ```
    pub fn taken(
        domain: impl Into<String>,
        tld: impl Into<String>,
        registrar: Option<String>,
        expiry_date: Option<DateTime<Utc>>,
    ) -> Self {
        CheckResult {
            domain: domain.into(),
            tld: tld.into(),
            status: CheckStatus::Taken,
            registrar,
            expiry_date,
            error_message: None,
            checked_at: Utc::now(),
        }
    }
}

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

    #[test]
    fn test_creates_taken_result_without_registrar() {
        let result = CheckResult::taken("example", "com", None, None);
        assert_eq!(result.domain, "example");
        assert_eq!(result.status, CheckStatus::Taken);
        assert!(result.registrar.is_none());
    }

    #[test]
    fn test_creates_taken_result_with_registrar() {
        let result = CheckResult::taken("google", "com", Some("Markmonitor Inc.".to_string()), None);
        assert_eq!(result.registrar, Some("Markmonitor Inc.".to_string()));
    }
}
