use std::collections::HashMap;

use dag_flow::engine::Engine;
use dag_flow::task::Input;
use dag_flow::task::Task;

fn main() {
    let builder = Engine::builder();
    builder
        .add_task(Void::from(1, vec![3]))
        .add_task(Void::from(2, vec![1]))
        .add_task(Void::from(3, vec![2]));

    assert_eq!(
        builder.build().err().map(|err| err.to_string()),
        Some("failed to build DAG: cycle detected in directed graph".into())
    );
}

struct Void {
    id: usize,
    dependencies: Vec<usize>,
}

impl Void {
    fn from(id: usize, dependencies: Vec<usize>) -> Self {
        Self { id, dependencies }
    }
}

impl Task<usize, ()> for Void {
    fn id(&self) -> usize {
        self.id
    }

    fn dependencies(&self) -> Vec<usize> {
        self.dependencies.clone()
    }

    async fn run(&self, _: HashMap<usize, Input<'_, ()>>) -> Option<()> {
        None
    }
}
