use crate::{
    commands::{Cli, Result},
    jobber::JobberDelete,
    print_tip,
};
use clap::Parser;
use color_print::cprintln;

/// Restore deleted tag
#[derive(Parser, Debug)]
pub(crate) struct RestoreTag {
    /// Tag's identifier
    id: String,
}

impl RestoreTag {
    pub(crate) fn run(&self, cli: &Cli) -> Result<()> {
        let mut database = cli.open_database()?;
        database.delete_tag(&self.id, false)?;
        cli.close_database(database)?;
        cprintln!("Successfully restored tag <s>{}</>.", self.id);
        print_tip!(cli,);
        print_tip!(cli, "Use <s>jobber undo</> to re-delete the tag.",);
        print_tip!(cli, "Use <s>jobber list tags</> to list tags.");
        Ok(())
    }
}
