use anyhow::Result;
use clap::Args;
use tonic::Request;

use crate::{InterceptedCdkMintClient, UpdateNameRequest};

/// Command to update the mint's name
///
/// This command sets a new display name for the mint, which is used to identify
/// the mint in wallet applications and other client interfaces.
#[derive(Args, Debug)]
pub struct UpdateNameCommand {
    /// The new name for the mint
    name: String,
}

/// Executes the update_name command against the mint server
///
/// This function sends an RPC request to update the mint's display name.
///
/// # Arguments
/// * `client` - The RPC client used to communicate with the mint
/// * `sub_command_args` - The new name to set for the mint
pub async fn update_name(
    client: &mut InterceptedCdkMintClient,
    sub_command_args: &UpdateNameCommand,
) -> Result<()> {
    let _response = client
        .update_name(Request::new(UpdateNameRequest {
            name: sub_command_args.name.clone(),
        }))
        .await?;

    Ok(())
}
