use std::{
    path::Path,
    str::FromStr,
    time::{Duration, SystemTime},
};

use radicle_ci_broker::{
    ergo::Oid,
    msg::{RepoId, RunId},
};

use radicle_native_ci::{runlog::RunLog, runspec::RunSpec};

/// The main program.
fn main() {
    let mut run_log = RunLog::new(Path::new("testlog.html"));
    run_log.started(SystemTime::now());
    run_log.duration(Duration::from_millis(500));
    run_log.adapter_run_id(RunId::from("plugh"));
    run_log.title("Some Title");
    run_log.rid(
        RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"),
        "colossal",
    );
    run_log.commit(Oid::from_str("b788f7ffd38572614457adb1656c0b4575b941dd").expect("commit"));
    run_log.branch("xyzzy");
    run_log.patch(
        Oid::from_str("e676fde7bfc7f8d433b50d73a236601d1f63cec3").unwrap(),
        "This be my patch",
    );
    run_log.runspec(RunSpec {
        shell: "echo hello, world".into(),
    });
    let started = SystemTime::now();
    let ended = SystemTime::now();
    run_log.runcmd(
        &["git", "pull"],
        Path::new("/tmp"),
        0,
        "This is stdout".as_bytes(),
        started,
        ended,
    );
    run_log.runcmd(
        &["cargo", "check", "--all-targets", "--workspace"],
        Path::new("/tmp"),
        0,
        "This is stdout".as_bytes(),
        started,
        ended,
    );

    run_log.write().expect("write html log");
}
