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

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

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