//! Internal wire-format types for the Anthropic Messages API.
use serde::{Deserialize, Serialize};

/// Base URL for the Anthropic Messages API.
pub(crate) const ANTHROPIC_API_URL: &str = "https://api.anthropic.com/v1/messages";
/// API version header value.
pub(crate) const ANTHROPIC_VERSION: &str = "2023-06-01";

/// A single message in an Anthropic conversation.
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct AnthropicMessage {
    pub(crate) role: String,
    pub(crate) content: AnthropicContent,
}

/// Message content: either plain text or a sequence of content blocks.
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub(crate) enum AnthropicContent {
    Text(String),
    Blocks(Vec<AnthropicContentBlock>),
}

/// A typed content block within an Anthropic message.
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub(crate) enum AnthropicContentBlock {
    #[serde(rename = "text")]
    Text { text: String },
    #[serde(rename = "tool_use")]
    ToolUse {
        id: String,
        name: String,
        input: serde_json::Value,
    },
    #[serde(rename = "tool_result")]
    ToolResult {
        tool_use_id: String,
        content: String,
    },
}

/// Tool definition sent to the Anthropic API.
#[derive(Debug, Serialize)]
pub(crate) struct AnthropicTool {
    pub(crate) name: String,
    pub(crate) description: String,
    pub(crate) input_schema: serde_json::Value,
}

/// A server-sent event from the Anthropic streaming API.
#[derive(Debug, Deserialize)]
pub(crate) struct StreamEvent {
    #[serde(rename = "type")]
    pub(crate) event_type: String,
    #[serde(flatten)]
    pub(crate) data: serde_json::Value,
}
