use crate::ham::Ham;
use crate::CommonOpts;
use anyhow::Result;
use holochain_types::dna::ActionHash;
use rave_engine::types::entries::{
    pool::swim_lane_definition::{SwimLaneDefinition, SwimLaneDefinitionExt},
    SwimLaneExt,
};

pub async fn create_swim_lane_definition(value: CommonOpts, definition: String) -> Result<()> {
    let agent = Ham::connect(value).await?;

    let definition: SwimLaneDefinition = serde_json::from_str(&definition)?;

    let result: ActionHash = agent
        .zome_call(
            "alliance",
            "transactor",
            "create_swim_lane_definition",
            definition,
        )
        .await?;

    println!("===================");
    println!("Swim Lane Definition Created:");
    println!("Action Hash: {:#?}", result);
    println!("===================");

    Ok(())
}

pub async fn update_swim_lane_definition(value: CommonOpts, definition: String) -> Result<()> {
    let agent = Ham::connect(value).await?;

    let definition: SwimLaneDefinitionExt = serde_json::from_str(&definition)?;

    let result: ActionHash = agent
        .zome_call(
            "alliance",
            "transactor",
            "update_swim_lane_definition",
            definition,
        )
        .await?;

    println!("===================");
    println!("Swim Lane Definition Updated:");
    println!("Action Hash: {:#?}", result);
    println!("===================");

    Ok(())
}

pub async fn get_all_swim_lane(value: CommonOpts) -> Result<()> {
    let agent = Ham::connect(value).await?;

    let result: Vec<SwimLaneExt> = agent
        .zome_call("alliance", "transactor", "get_all_swim_lane", ())
        .await?;

    println!("===================");
    println!("All Swim Lanes:");
    println!("{:#?}", result);
    println!("===================");

    Ok(())
}
