use vta_cli_common::commands::elections::{self, VoteTarget};
use vta_cli_common::commands::elections_trustee::{self as trustee, TrusteeTarget};
use vta_sdk::client::VtaClient;
use crate::cli::{ElectionCommands, ElectionTarget, MembershipPresenting, TrusteeCommands};
fn target(t: &ElectionTarget) -> VoteTarget<'_> {
VoteTarget {
vtc_url: &t.vtc,
vtc_did: &t.vtc_did,
member: &t.member,
context: &t.context,
}
}
fn presenting(p: &MembershipPresenting) -> elections::Presenting<'_> {
elections::Presenting {
credential: p.membership_credential.as_deref(),
member_of: p.member_of.as_deref(),
}
}
fn trustee_target(t: &crate::cli::TrusteeTarget) -> TrusteeTarget<'_> {
TrusteeTarget {
community: &t.community,
ballot_box: &t.ballot_box,
trustee: &t.trustee,
context: &t.context,
}
}
pub(crate) async fn run(
client: &VtaClient,
command: ElectionCommands,
) -> Result<(), Box<dyn std::error::Error>> {
match command {
ElectionCommands::List { target: t } => elections::cmd_list(client, target(&t)).await,
ElectionCommands::Show {
election_id,
target: t,
presenting: p,
} => elections::cmd_show_presenting(client, target(&t), &election_id, presenting(&p)).await,
ElectionCommands::Ticket {
election_id,
target: t,
presenting: p,
} => {
elections::cmd_ticket_presenting(client, target(&t), &election_id, presenting(&p)).await
}
ElectionCommands::Vote {
election_id,
answers,
ballot,
now,
no_delay,
target: t,
} => {
elections::cmd_vote(
client,
target(&t),
&election_id,
&answers,
ballot.as_ref(),
now,
no_delay,
)
.await
}
ElectionCommands::Verify {
election_id,
target: t,
} => elections::cmd_verify(client, target(&t), &election_id).await,
ElectionCommands::Trustee(TrusteeCommands::Status {
election_id,
target: t,
}) => trustee::cmd_status(client, trustee_target(&t), &election_id).await,
ElectionCommands::Trustee(TrusteeCommands::Step {
election_id,
watch,
target: t,
}) => trustee::cmd_step(client, trustee_target(&t), &election_id, watch).await,
}
}