Documentation
use std::fmt::Display;

use sts::readable;

#[derive(Debug)]
pub struct Warn {
  pub watch_id: u16,
  pub watch_name: &'static str,
  pub host: Box<str>,
  pub tag_li: Box<[String]>,
  pub duration: u64,
  pub err: aok::Error,
}

#[derive(Debug)]
pub struct Recover {
  pub watch_id: u16,
  pub watch_name: &'static str,
  pub host: Box<str>,
  pub tag_li: Box<[String]>,
  pub duration: u64,
}

pub enum Msg {
  Warn(Warn),
  Recover(Recover),
  None,
}

macro_rules! display {
  ($self:ident,$f:ident) => {{
    write!($f, " {} : {}", $self.watch_name, $self.host)?;
    if !$self.tag_li.is_empty() {
      write!($f, "( ")?;
      for (n, i) in $self.tag_li.iter().enumerate() {
        if n > 0 {
          write!($f, " / ")?;
        }
        write!($f, "{}", i)?;
      }
      write!($f, " )")?;
    }
    write!($f, "{}", readable($self.duration))?;
  }};
}

impl Display for Recover {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "")?;
    display!(self, f);
    Ok(())
  }
}

impl Display for Warn {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "")?;
    display!(self, f);
    write!(f, "\n{}", self.err)?;
    Ok(())
  }
}