//! Session event types.
//!
//! Events emitted by `SessionManager` to notify about session lifecycle changes.

use std::path::PathBuf;

use super::command::AutoInputStep;
use crate::session::SessionId;

/// Events emitted by `SessionManager`
#[derive(Debug, Clone)]
pub enum SessionEvent {
    /// Session created
    Created {
        /// New session ID
        id: SessionId,
        /// Branch name (if worktree was created)
        branch: Option<String>,
        /// Auto-input steps to execute (handled by `TuiApp`)
        auto_input: Vec<AutoInputStep>,
    },
    /// Output received from session
    Output {
        /// Source session
        id: SessionId,
        /// Output data
        data: Vec<u8>,
    },
    /// Terminal title changed (OSC sequence detected)
    TitleChanged {
        /// Source session
        id: SessionId,
        /// New title
        title: String,
    },
    /// Session terminated
    Terminated {
        /// Terminated session
        id: SessionId,
        /// Exit code if available
        exit_code: Option<i32>,
    },
    /// Error occurred
    Error {
        /// Source session
        id: SessionId,
        /// Error message
        error: String,
    },
    /// Worktrees refreshed (async operation completed/in-progress)
    WorktreesRefreshed {
        /// Updated worktree list
        worktrees: Vec<crate::worktree::WorktreeInfo>,
        /// True if git fetch is still pending (more updates coming)
        fetch_pending: bool,
    },
    /// Worktree deleted (async delete completed)
    WorktreeDeleted {
        /// Path of the deleted worktree
        path: PathBuf,
        /// Result of the delete operation
        result: Result<(), String>,
    },
    /// Worktree pulled (async pull completed)
    WorktreePulled {
        /// Path of the pulled worktree
        path: PathBuf,
        /// Result of the pull operation (includes updated git status on success)
        result: Result<crate::worktree::GitWorktreeStatus, String>,
    },
    /// Hook event received from Claude Code
    HookReceived {
        /// Hook event
        event: crate::hooks::HookEvent,
    },
    /// GitHub issues fetched
    IssuesFetched {
        /// Fetched issues (or error message)
        result: Result<Vec<crate::github::GitHubIssue>, String>,
    },
    /// Single issue fetched (phase 1 of issue loading)
    IssueFetched {
        /// Issue number
        issue_number: u32,
    },
    /// Action choices generated for a GitHub issue
    IssueActionsFetched {
        /// Issue number
        issue_number: u32,
        /// Generated action choices (or error message)
        result: Result<Vec<crate::github::ActionChoice>, String>,
    },
    /// Today's usage cost fetched from ccusage
    CostFetched {
        /// Cost in USD (None if unavailable)
        cost: Option<f64>,
    },
}
