use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParsedConversation {
    pub id: String,           // ChatGPT's conversation_id (hex-ish; may or may not be a UUID)
    pub title: Option<String>,
    pub created_at: Option<DateTime<Utc>>,
    pub updated_at: Option<DateTime<Utc>>,
    pub messages: Vec<ParsedMessage>,
    #[serde(default)]
    pub metadata: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParsedMessage {
    pub id: String,
    pub role: String,             // "user" | "assistant" | "system" | "tool"
    pub ts: Option<DateTime<Utc>>,
    pub content: Vec<ContentPart>,
    #[serde(default)]
    pub metadata: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContentPart {
    Text { text: String },
    Code { language: Option<String>, text: String },
    Tool { name: String, input: serde_json::Value, output: Option<serde_json::Value> },
}
