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

/// A Codex session parsed from a single JSONL file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParsedSession {
    /// The native session id. For Codex this is the JSONL file stem.
    pub native_id:   String,
    /// The source file the session was loaded from.
    pub source_path: PathBuf,
    /// First message timestamp seen (if any).
    pub created_at:  Option<DateTime<Utc>>,
    /// Last message timestamp seen (if any).
    pub updated_at:  Option<DateTime<Utc>>,
    /// Parsed messages in file order.
    pub messages:    Vec<ParsedMessage>,
}

/// A single message event from a Codex JSONL session file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParsedMessage {
    /// Timestamp if one could be extracted (RFC 3339 or unix epoch).
    pub ts:       Option<DateTime<Utc>>,
    /// Free-form role, e.g. "user", "assistant", "system", "tool".
    pub role:     String,
    /// Best-effort concatenated text content.
    pub content:  String,
    /// Raw event for provenance.
    #[serde(default)]
    pub metadata: serde_json::Value,
}
