use serde::{Deserialize, Serialize};

/// MCP-style content block for displayable content
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContentBlock {
    Text {
        text: String,
    },
    ResourceLink {
        uri: String,
        #[serde(skip_serializing_if = "Option::is_none")]
        name: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")]
        mime_type: Option<String>,
    },
    // Future: Resource, Image, Audio (marked as out-of-scope for phase 1)
}

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

    #[test]
    fn test_text_serialization() {
        let block = ContentBlock::Text {
            text: "Hello".to_string(),
        };
        let json = serde_json::to_string(&block).unwrap();
        assert!(json.contains(r#""type":"text"#));
        assert!(json.contains(r#""text":"Hello"#));
    }

    #[test]
    fn test_resource_link_serialization() {
        let block = ContentBlock::ResourceLink {
            uri: "file:///path/to/file".to_string(),
            name: Some("file.txt".to_string()),
            mime_type: Some("text/plain".to_string()),
        };
        let json = serde_json::to_string(&block).unwrap();
        assert!(json.contains(r#""type":"resource_link"#));
        assert!(json.contains(r#""uri":"file:///path/to/file"#));
    }

    #[test]
    fn test_roundtrip() {
        let block = ContentBlock::Text {
            text: "Test".to_string(),
        };
        let json = serde_json::to_string(&block).unwrap();
        let deserialized: ContentBlock = serde_json::from_str(&json).unwrap();
        assert_eq!(block, deserialized);
    }
}
