use super::session::SlashCommand;
use super::session_id::UnifiedSessionId;

/// Dialog information returned by SessionManager
#[derive(Debug, Clone)]
pub struct DialogInfo {
    pub session_id: UnifiedSessionId,
    pub title: String,
    pub created_at: i64,
    pub last_active_at: i64,
    pub message_count: i64,
    pub archived_at: Option<i64>,
}

/// Session events emitted by SessionManager to Channel
#[derive(Debug, Clone)]
pub enum SessionEvent {
    /// A new dialog was created
    DialogCreated {
        session_id: UnifiedSessionId,
        title: String,
    },
    /// List of dialogs returned
    DialogList {
        dialogs: Vec<DialogInfo>,
        current_dialog_id: Option<String>,
    },
    /// Current dialog info returned
    CurrentDialog {
        session_id: Option<UnifiedSessionId>,
    },
    /// Dialog switched successfully
    DialogSwitched { session_id: UnifiedSessionId },
    /// Persisted dialog messages, ordered by sequence.
    DialogHistory {
        session_id: UnifiedSessionId,
        messages: Vec<crate::storage::message::MessageMeta>,
    },
    /// Active task plan for a dialog, if present.
    TaskPlan {
        session_id: UnifiedSessionId,
        plan: Option<crate::work::TaskPlan>,
    },
    /// Provider usage totals and current context-window state.
    SessionStats { stats: crate::session::SessionStats },
    /// Durable Agent run projection page for a dialog.
    AgentRuns {
        session_id: UnifiedSessionId,
        revision: i64,
        runs: Vec<crate::protocol::AgentRunView>,
        next_cursor: Option<String>,
    },
    /// One durable Agent run projection.
    AgentRun {
        session_id: UnifiedSessionId,
        revision: i64,
        run: Option<crate::protocol::AgentRunView>,
    },
    /// Dialog renamed
    DialogRenamed {
        session_id: UnifiedSessionId,
        title: String,
    },
    /// Dialog archived
    DialogArchived { session_id: UnifiedSessionId },
    /// Dialog deleted
    DialogDeleted { session_id: UnifiedSessionId },
    /// Dialog history cleared
    HistoryCleared { session_id: UnifiedSessionId },
    /// List of available slash commands
    SlashCommandsList { commands: Vec<SlashCommand> },
    /// Slash command executed successfully
    SlashCommandExecuted {
        new_session_id: Option<UnifiedSessionId>,
        message: String,
    },
    /// Context compression completed
    ContextCompressed {
        original_count: usize,
        compressed_count: usize,
    },
    /// Session information
    SessionInfo {
        session_id: String,
        message_count: usize,
    },
    /// Error occurred
    Error { code: String, message: String },
}
