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

/// Delete a job.
///
/// Job will be marked as deleted and can be restored later.
#[derive(Parser, Debug)]
pub(crate) struct DeleteJob {
    /// Job's identifier
    id: usize,
}

impl DeleteJob {
    pub(crate) fn run(&self, cli: &Cli) -> Result<()> {
        let mut database = cli.open_database()?;
        database.delete_job(self.id, true)?;
        cli.close_database(database)?;
        cprintln!("Successfully deleted job <s>{}</>.", self.id);
        print_tip!(cli);
        print_tip!(cli, "Use <s>jobber undo</> to restore the job.");
        print_tip!(cli, "Use <s>jobber list jobs -d</> to list deleted jobs.");
        Ok(())
    }
}
