use clap::{Args, Subcommand};
use szamlazz_agent::ops::proforma::{DeleteProforma, ProformaSelector};
use crate::output;
#[derive(Debug, Subcommand)]
pub enum ProformaCommand {
Delete(DeleteArgs),
}
#[derive(Debug, Args)]
pub struct DeleteArgs {
number: Option<String>,
#[arg(long, conflicts_with = "number")]
order: Option<String>,
}
pub async fn run(cli: &crate::Cli, command: &ProformaCommand) -> anyhow::Result<()> {
let ProformaCommand::Delete(args) = command;
let selector = match (&args.number, &args.order) {
(Some(number), None) => ProformaSelector::InvoiceNumber(number.as_str().into()),
(None, Some(order)) => ProformaSelector::OrderNumber(order.clone()),
_ => anyhow::bail!("pass a proforma number or --order"),
};
let client = crate::client(cli)?;
client.send(&DeleteProforma::new(selector)).await?;
if cli.json {
output::json(&serde_json::json!({ "deleted": true }))?;
} else {
println!("Proforma deleted.");
}
Ok(())
}