use serde::Serialize;

use crate::{host::Host, media::Media};

#[derive(Debug, Serialize)]
pub struct TestReport {
    ok: bool,
    host: Host,
    time_in_ms: u128,
    description: String,
}

impl TestReport {
    pub fn new(ok: bool, host: Host, time_in_ms: u128, description: String) -> Self {
        Self {
            ok,
            host,
            time_in_ms,
            description,
        }
    }

    pub fn print_to(&self, an_output_device: &mut impl Media) {
        an_output_device.print(serde_json::to_string(self).unwrap().as_bytes());
    }

    pub fn ok(&self) -> bool {
        self.ok
    }

    pub fn host_name(&self) -> &str {
        &self.host.name()
    }
}
