//! Tauri commands for snapshotting (git-backed history).

use crate::state::AppState;
use brittle_core::Snapshot;
use tauri::State;

#[tauri::command]
pub fn create_snapshot(state: State<AppState>, message: String) -> Result<Snapshot, String> {
    state.with_repo(|b| b.create_snapshot(&message))
}

#[tauri::command]
pub fn list_snapshots(state: State<AppState>) -> Result<Vec<Snapshot>, String> {
    state.with_repo_read(|b| b.list_snapshots())
}

/// Restore to a named snapshot. Fails if there are uncommitted changes.
/// Use `discard_changes` first if needed.
#[tauri::command]
pub fn restore_snapshot(state: State<AppState>, snapshot_id: String) -> Result<(), String> {
    state.with_repo(|b| b.restore_snapshot(&snapshot_id))
}

#[tauri::command]
pub fn has_uncommitted_changes(state: State<AppState>) -> Result<bool, String> {
    state.with_repo_read(|b| b.has_uncommitted_changes())
}

/// Discard all uncommitted changes, reverting to the last snapshot.
#[tauri::command]
pub fn discard_changes(state: State<AppState>) -> Result<(), String> {
    state.with_repo(|b| b.discard_changes())
}
