use super::WizardState;
use crate::utils::permissions;
use crate::wizard::error::WizardError;
use std::path::PathBuf;
pub struct ProgressManager {
state_file: PathBuf,
}
impl ProgressManager {
pub fn new() -> anyhow::Result<Self> {
let cache_dir = dirs::cache_dir().unwrap().join("agentswitch");
permissions::create_directory_with_700_perms(&cache_dir)?;
let state_file = cache_dir.join("wizard_state.toml");
Ok(Self { state_file })
}
pub fn save_state(&self, state: &WizardState) -> Result<(), WizardError> {
state.save(&self.state_file)
}
pub fn load_state(&self) -> Result<Option<WizardState>, WizardError> {
WizardState::load(&self.state_file)
}
pub fn clear_state(&self) -> Result<(), WizardError> {
if self.state_file.exists() {
std::fs::remove_file(&self.state_file)?;
}
Ok(())
}
pub fn state_file_path(&self) -> &PathBuf {
&self.state_file
}
}
impl Default for ProgressManager {
fn default() -> Self {
Self::new().unwrap()
}
}