use anyhow::{bail, Result};
use clap::Args;
use tonic::Request;
use crate::quote::{MintQuoteState, UpdateMintQuoteStateRequest};
use crate::InterceptedQuoteServiceClient;
#[derive(Args, Debug)]
pub struct UpdateMintQuoteStateCommand {
quote_id: String,
#[arg(default_value = "PAID")]
state: String,
}
pub async fn update_mint_quote_state(
client: &mut InterceptedQuoteServiceClient,
sub_command_args: &UpdateMintQuoteStateCommand,
) -> Result<()> {
let state = match sub_command_args.state.as_str() {
"UNPAID" => MintQuoteState::Unpaid,
"PAID" => MintQuoteState::Paid,
"ISSUED" => MintQuoteState::Issued,
state => bail!("Invalid quote state: {state}"),
};
let response = client
.update_mint_quote_state(Request::new(UpdateMintQuoteStateRequest {
quote_id: sub_command_args.quote_id.clone(),
state: state.into(),
}))
.await?;
let response = response.into_inner();
println!(
"Quote {} updated to {}",
response.quote_id,
state_name(response.state())
);
Ok(())
}
fn state_name(state: MintQuoteState) -> &'static str {
match state {
MintQuoteState::Unspecified => "UNSPECIFIED",
MintQuoteState::Unpaid => "UNPAID",
MintQuoteState::Paid => "PAID",
MintQuoteState::Issued => "ISSUED",
}
}