use anyhow::Result;
use clap::{Args, Subcommand};
use grr_gmail::GmailClient;
#[derive(Subcommand, Debug)]
pub enum ThreadCommands {
Label(LabelArgs),
Trash(TrashArgs),
Untrash(UntrashArgs),
Delete(DeleteArgs),
}
#[derive(Args, Debug)]
pub struct LabelArgs {
pub thread_id: String,
#[arg(long, value_delimiter = ',')]
pub add: Vec<String>,
#[arg(long, value_delimiter = ',')]
pub remove: Vec<String>,
}
#[derive(Args, Debug)]
pub struct TrashArgs {
pub thread_id: String,
}
#[derive(Args, Debug)]
pub struct UntrashArgs {
pub thread_id: String,
}
#[derive(Args, Debug)]
pub struct DeleteArgs {
pub thread_id: String,
}
pub async fn handle_thread_cmd(client: &GmailClient, cmd: ThreadCommands) -> Result<()> {
match cmd {
ThreadCommands::Label(args) => {
client
.modify_thread_labels(&args.thread_id, &args.add, &args.remove)
.await?;
println!("Labels updated for thread {}", args.thread_id);
}
ThreadCommands::Trash(args) => {
client.trash_thread(&args.thread_id).await?;
println!("Thread {} moved to trash", args.thread_id);
}
ThreadCommands::Untrash(args) => {
client.untrash_thread(&args.thread_id).await?;
println!("Thread {} restored from trash", args.thread_id);
}
ThreadCommands::Delete(args) => {
client.delete_thread(&args.thread_id).await?;
println!("Thread {} permanently deleted", args.thread_id);
}
}
Ok(())
}