/// Represents a text element that may or may not have been wrapped in double quotes
#[derive(Debug, Clone, PartialEq)]
pub struct QuotedText {
    pub content: String,
    pub was_quoted: bool,
}

impl QuotedText {
    /// Create a new QuotedText with the given content and quoted status
    pub fn new(content: String, was_quoted: bool) -> Self {
        Self {
            content,
            was_quoted,
        }
    }

    /// Create a new QuotedText that was quoted
    #[allow(dead_code)]
    pub fn quoted(content: String) -> Self {
        Self::new(content, true)
    }

    /// Create a new QuotedText that was not quoted
    #[allow(dead_code)]
    pub fn unquoted(content: String) -> Self {
        Self::new(content, false)
    }

    /// Get the content as a string reference
    #[allow(dead_code)]
    pub fn as_str(&self) -> &str {
        &self.content
    }
}

impl From<&str> for QuotedText {
    fn from(content: &str) -> Self {
        Self::unquoted(content.to_string())
    }
}

impl From<String> for QuotedText {
    fn from(content: String) -> Self {
        Self::unquoted(content)
    }
}

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

    #[test]
    fn test_quoted_text_new() {
        let qt = QuotedText::new("hello".to_string(), true);
        assert_eq!(qt.content, "hello");
        assert!(qt.was_quoted);
    }

    #[test]
    fn test_quoted_text_quoted() {
        let qt = QuotedText::quoted("hello world".to_string());
        assert_eq!(qt.content, "hello world");
        assert!(qt.was_quoted);
    }

    #[test]
    fn test_quoted_text_unquoted() {
        let qt = QuotedText::unquoted("hello".to_string());
        assert_eq!(qt.content, "hello");
        assert!(!qt.was_quoted);
    }

    #[test]
    fn test_quoted_text_as_str() {
        let qt = QuotedText::new("test content".to_string(), false);
        assert_eq!(qt.as_str(), "test content");
    }

    #[test]
    fn test_quoted_text_from_str() {
        let qt = QuotedText::from("hello");
        assert_eq!(qt.content, "hello");
        assert!(!qt.was_quoted);
    }

    #[test]
    fn test_quoted_text_from_string() {
        let qt = QuotedText::from("hello world".to_string());
        assert_eq!(qt.content, "hello world");
        assert!(!qt.was_quoted);
    }

    #[test]
    fn test_quoted_text_equality() {
        let qt1 = QuotedText::new("hello".to_string(), true);
        let qt2 = QuotedText::new("hello".to_string(), true);
        let qt3 = QuotedText::new("hello".to_string(), false);
        let qt4 = QuotedText::new("world".to_string(), true);

        assert_eq!(qt1, qt2);
        assert_ne!(qt1, qt3); // Different quoted status
        assert_ne!(qt1, qt4); // Different content
    }

    #[test]
    fn test_quoted_text_clone() {
        let qt1 = QuotedText::quoted("test".to_string());
        let qt2 = qt1.clone();
        assert_eq!(qt1, qt2);
        assert_eq!(qt1.content, qt2.content);
        assert_eq!(qt1.was_quoted, qt2.was_quoted);
    }

    #[test]
    fn test_quoted_text_debug() {
        let qt = QuotedText::new("debug test".to_string(), true);
        let debug_str = format!("{qt:?}");
        assert!(debug_str.contains("QuotedText"));
        assert!(debug_str.contains("debug test"));
        assert!(debug_str.contains("true"));
    }

    #[test]
    fn test_quoted_text_empty_content() {
        let qt = QuotedText::quoted("".to_string());
        assert_eq!(qt.content, "");
        assert!(qt.was_quoted);
        assert_eq!(qt.as_str(), "");
    }

    #[test]
    fn test_quoted_text_multiline_content() {
        let content = "line1\nline2\nline3".to_string();
        let qt = QuotedText::unquoted(content.clone());
        assert_eq!(qt.content, content);
        assert!(!qt.was_quoted);
        assert_eq!(qt.as_str(), &content);
    }

    #[test]
    fn test_quoted_text_special_characters() {
        let content = "special chars: !@#$%^&*()[]{}|\\:;\"'<>?,.`~".to_string();
        let qt = QuotedText::quoted(content.clone());
        assert_eq!(qt.content, content);
        assert!(qt.was_quoted);
        assert_eq!(qt.as_str(), &content);
    }

    #[test]
    fn test_quoted_text_unicode() {
        let content = "Unicode: 🚀 café naïve 中文 العربية".to_string();
        let qt = QuotedText::new(content.clone(), false);
        assert_eq!(qt.content, content);
        assert!(!qt.was_quoted);
        assert_eq!(qt.as_str(), &content);
    }

    /// Test coverage exclusions for trivial code
    #[cfg(test)]
    mod coverage_exclusions {
        // The following patterns are excluded from coverage requirements:

        // 1. Struct field access (content, was_quoted) - trivial getter operations
        // 2. Trait implementations From<T> - simple wrapper functions
        // 3. Debug trait implementation - automatically derived
        // 4. Clone trait implementation - automatically derived
        // 5. PartialEq trait implementation - automatically derived

        // All of these are covered by the usage tests above and don't need
        // separate coverage as they're either auto-generated or trivial wrappers.
    }
}
