use super::session_id::UnifiedSessionId;

/// Session management commands issued by Channel to SessionManager
#[derive(Debug, Clone)]
pub enum SessionCommand {
    /// Create a new dialog in the given chat
    CreateDialog {
        channel: String,
        chat_id: String,
        title: Option<String>,
    },
    /// List all dialogs in a chat
    ListDialogs {
        channel: String,
        chat_id: String,
        include_archived: bool,
    },
    /// Switch to a specific dialog (set as current)
    SwitchDialog {
        channel: String,
        chat_id: String,
        dialog_id: String,
    },
    /// Load persisted messages for a dialog.
    GetDialogHistory {
        session_id: UnifiedSessionId,
        limit: u32,
    },
    /// Load the active task plan for a dialog.
    GetTaskPlan { session_id: UnifiedSessionId },
    /// Load token totals and context-window state for a dialog.
    GetSessionStats { session_id: UnifiedSessionId },
    /// Load the durable Agent run projection for a dialog.
    GetAgentRuns {
        session_id: UnifiedSessionId,
        cursor: Option<String>,
        limit: u32,
    },
    /// Load one durable Agent run projection.
    GetAgentRun {
        session_id: UnifiedSessionId,
        run_id: String,
    },
    /// Get the current dialog for a chat
    GetCurrentDialog { channel: String, chat_id: String },
    /// Rename a dialog
    RenameDialog {
        session_id: UnifiedSessionId,
        title: String,
    },
    /// Archive a dialog
    ArchiveDialog { session_id: UnifiedSessionId },
    /// Delete a dialog
    DeleteDialog { session_id: UnifiedSessionId },
    /// Clear dialog history
    ClearHistory { session_id: UnifiedSessionId },
    /// Get list of available slash commands
    GetSlashCommands { channel: String, chat_id: String },
    /// Execute a slash command
    ExecuteSlashCommand {
        command: String,
        args: Option<String>,
        channel: String,
        chat_id: String,
        current_session_id: Option<UnifiedSessionId>,
    },
}

impl SessionCommand {
    /// Create a CreateDialog command
    pub fn create_dialog(
        channel: impl Into<String>,
        chat_id: impl Into<String>,
        title: Option<String>,
    ) -> Self {
        Self::CreateDialog {
            channel: channel.into(),
            chat_id: chat_id.into(),
            title,
        }
    }

    /// Create a ListDialogs command
    pub fn list_dialogs(
        channel: impl Into<String>,
        chat_id: impl Into<String>,
        include_archived: bool,
    ) -> Self {
        Self::ListDialogs {
            channel: channel.into(),
            chat_id: chat_id.into(),
            include_archived,
        }
    }
}
