//! Prompt message types for MCP prompts/get responses
//!
//! Per MCP spec, prompt responses have `messages` with `role` + `content`

use serde::{Deserialize, Serialize};

/// A single message in a prompt response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptMessage {
    /// Message role (user or assistant)
    pub role: PromptRole,

    /// Message content
    pub content: PromptContent,
}

/// Role in a prompt conversation
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PromptRole {
    /// User message
    User,

    /// Assistant message
    Assistant,
}

/// Content in a prompt message
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum PromptContent {
    /// Text content
    #[serde(rename = "text")]
    Text { text: String },

    /// Image content
    #[serde(rename = "image")]
    Image {
        data: String,
        #[serde(rename = "mimeType")]
        mime_type: String,
    },

    /// Resource content
    #[serde(rename = "resource")]
    Resource {
        uri: String,
        #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
        mime_type: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")]
        text: Option<String>,
    },
}

impl PromptMessage {
    /// Create a user message with text content
    pub fn user(text: impl Into<String>) -> Self {
        Self {
            role: PromptRole::User,
            content: PromptContent::Text { text: text.into() },
        }
    }

    /// Create an assistant message with text content
    pub fn assistant(text: impl Into<String>) -> Self {
        Self {
            role: PromptRole::Assistant,
            content: PromptContent::Text { text: text.into() },
        }
    }

    /// Create a user message with image content
    pub fn user_image(data: impl Into<String>, mime_type: impl Into<String>) -> Self {
        Self {
            role: PromptRole::User,
            content: PromptContent::Image {
                data: data.into(),
                mime_type: mime_type.into(),
            },
        }
    }

    /// Create an assistant message with image content
    pub fn assistant_image(data: impl Into<String>, mime_type: impl Into<String>) -> Self {
        Self {
            role: PromptRole::Assistant,
            content: PromptContent::Image {
                data: data.into(),
                mime_type: mime_type.into(),
            },
        }
    }
}
