use std::sync::Arc; use anyhow::Result; use clap::Subcommand; use tokio::sync::Mutex; use crate::{ app::App, cli::{CliCommandHandler, Command}, execute_network_event, network::{sonarr_network::SonarrEvent, NetworkTrait}, }; use super::SonarrCommand; #[cfg(test)] #[path = "delete_command_handler_tests.rs"] mod delete_command_handler_tests; #[derive(Debug, Clone, PartialEq, Eq, Subcommand)] pub enum SonarrDeleteCommand { #[command(about = "Delete the specified item from the Sonarr blocklist")] BlocklistItem { #[arg( long, help = "The ID of the blocklist item to remove from the blocklist", required = true )] blocklist_item_id: i64, }, } impl From for Command { fn from(value: SonarrDeleteCommand) -> Self { Command::Sonarr(SonarrCommand::Delete(value)) } } pub(super) struct SonarrDeleteCommandHandler<'a, 'b> { _app: &'a Arc>>, command: SonarrDeleteCommand, network: &'a mut dyn NetworkTrait, } impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteCommandHandler<'a, 'b> { fn with( _app: &'a Arc>>, command: SonarrDeleteCommand, network: &'a mut dyn NetworkTrait, ) -> Self { SonarrDeleteCommandHandler { _app, command, network, } } async fn handle(self) -> Result<()> { match self.command { SonarrDeleteCommand::BlocklistItem { blocklist_item_id } => { execute_network_event!( self, SonarrEvent::DeleteBlocklistItem(Some(blocklist_item_id)) ); } } Ok(()) } }