use domino_cli::*;
use structopt::StructOpt;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let cli = Cli::from_args();

    match cli.cmd {
        Command::Dashboard => actions::dashboard::dashboard(cli.common).await?,
        Command::ProgenitorCommand(cmd) => match cmd {
            ProgenitorCommand::Dashboard => actions::dashboard::dashboard(cli.common).await?,
            ProgenitorCommand::Init { library_path } => {
                actions::progenitor::init(cli.common, library_path).await?
            }
            ProgenitorCommand::InitializePoolDefinition => {
                actions::zome_call::pool::initialize_pool_definition(
                    cli.common, None, None, None, None, None, None,
                )
                .await?
            }
            ProgenitorCommand::GetPoolDefinitions => {
                actions::zome_call::pool::get_current_pool_definition(cli.common).await?
            }
            ProgenitorCommand::AddPoolPieces(piece_definition) => {
                actions::zome_call::pool::add_pool_pieces(cli.common, piece_definition).await?
            }
            ProgenitorCommand::UpdatePoolPieces(piece_definition) => {
                actions::zome_call::pool::update_pool_pieces(cli.common, piece_definition).await?
            }
            ProgenitorCommand::GetPoolPiecesDetails => {
                actions::zome_call::pool::get_pool_pieces_details(cli.common).await?
            }
            ProgenitorCommand::CreateSwimLaneDefinition { definition } => {
                actions::zome_call::swim_lane::create_swim_lane_definition(cli.common, definition)
                    .await?
            }
            ProgenitorCommand::UpdateSwimLaneDefinition { definition } => {
                actions::zome_call::swim_lane::update_swim_lane_definition(cli.common, definition)
                    .await?
            }
            ProgenitorCommand::GetAllSwimLane => {
                actions::zome_call::swim_lane::get_all_swim_lane(cli.common).await?
            }
        },
        Command::ZomeCommand(cmd) => match cmd {
            ZomeCommand::WhoAmI => {
                _ = actions::dashboard::whoami(cli.common).await?;
                return Ok(());
            }
            ZomeCommand::GetLedger => actions::dashboard::get_ledger(cli.common).await?,
            ZomeCommand::GetPending => actions::dashboard::get_pending(cli.common).await?,
            ZomeCommand::GetActionableTransactions => {
                actions::dashboard::get_actionable_transactions(cli.common).await?
            }
            ZomeCommand::GetCompleted => actions::dashboard::get_completed(cli.common).await?,
            ZomeCommand::CreateSpend {
                receiver,
                amount,
                note,
                auto_credit_check,
            } => {
                actions::zome_call::transactions::create_spend(
                    cli.common,
                    receiver,
                    amount,
                    note,
                    auto_credit_check,
                )
                .await?
            }
            ZomeCommand::CreateInvoice {
                spender,
                amount,
                note,
            } => {
                actions::zome_call::transactions::create_invoice(cli.common, spender, amount, note)
                    .await?
            }
            ZomeCommand::AcceptTransaction {
                address,
                auto_credit_check,
            } => {
                actions::zome_call::transactions::accept_transaction(
                    cli.common,
                    address,
                    auto_credit_check,
                )
                .await?
            }
            ZomeCommand::GetParkedSpend => {
                actions::zome_call::transactions::get_parked_spend(cli.common).await?
            }
            ZomeCommand::ExecuteRave { input } => {
                actions::zome_call::rave::execute_rave(cli.common, input).await?
            }
            ZomeCommand::GetIncomingRaves => {
                actions::zome_call::rave::get_incoming_raves(cli.common).await?
            }
            ZomeCommand::AcceptRave { rave } => {
                actions::zome_call::rave::collect_from_rave(cli.common, rave).await?
            }
            ZomeCommand::GetPoolDefinitions => {
                actions::zome_call::pool::get_current_pool_definition(cli.common).await?
            }
            ZomeCommand::GetPoolPiecesDetails => {
                actions::zome_call::pool::get_pool_pieces_details(cli.common).await?
            }
            ZomeCommand::GetAllSwimLanes => {
                actions::zome_call::swim_lane::get_all_swim_lane(cli.common).await?
            }
            ZomeCommand::GetCodeTemplatesLib => {
                _ = actions::zome_call::rave::get_code_templates_lib(cli.common).await?
            }
        },
    }

    Ok(())
}
