use crate::yabridge::types::{Plugin, PluginOptions, SyncOptions};
use std::path::PathBuf;

/// Actions that can be dispatched through the application
#[derive(Debug, Clone)]
pub enum Action {
    /// Do nothing
    Noop,
    /// Quit the application
    Quit,
    /// Periodic tick
    Tick,

    // ── Navigation ──────────────────────────────
    /// Switch to next tab
    NextTab,
    /// Switch to previous tab
    PrevTab,

    // ── yabridge operations ─────────────────────
    /// Trigger a plugin sync
    SyncPlugins(SyncOptions),
    /// Sync finished (Ok = output, Err = error message)
    SyncComplete(Result<String, String>),
    /// A new line of sync output arrived
    SyncOutputLine(String),
    /// Refresh the plugin list from yabridgectl status
    RefreshPlugins,
    /// Plugin list has been refreshed with data
    PluginsLoaded(Vec<Plugin>),
    /// Plugin refresh failed
    PluginsError(String),
    /// Add a plugin directory path
    AddPath(PathBuf),
    /// Path added result
    PathAdded(Result<String, String>),
    /// Remove a plugin directory path
    RemovePath(PathBuf),
    /// Path removed result
    PathRemoved(Result<String, String>),
    /// Refresh paths list
    RefreshPaths,
    /// Paths list loaded with data
    PathsLoaded(Vec<PathBuf>),
    /// Paths refresh failed
    PathsError(String),

    // ── Config operations ───────────────────────
    /// Reload config from disk
    RefreshConfig,
    /// Save current config rules to yabridge.toml
    SaveConfig(String, Vec<PluginOptions>),
    /// Config save result
    ConfigSaved(Result<String, String>),
    /// Add a new config rule with given pattern
    AddConfigRule(String),
    /// Delete config rule at index
    DeleteConfigRule(usize),
    /// Edit a config field: (rule_index, field_index, new_value)
    EditConfigField(usize, usize, String),
    /// Edit a config rule pattern: (rule_index, new_pattern)
    EditConfigPattern(usize, String),

    // ── UI state ────────────────────────────────
    /// Show a confirmation popup with a typed action to run on confirm
    ShowConfirm {
        message: String,
        on_confirm: Box<Action>,
    },
    /// Show an input popup for text entry
    ShowInput(String),
    /// Toggle help overlay
    ToggleHelp,
    /// Cycle to the next color theme
    CycleTheme,
}
