#[derive(
  Clone, Debug, serde::Deserialize, serde::Serialize, Default, bincode::Decode, bincode::Encode,
)]
pub struct BlockHeader {
  pub previous_hash: String,
  pub timestamp: u64,
  pub merkle_root: String,
  pub block_hash: String,
  pub nonce: u32,
  pub height: u64,
}

#[derive(
  Clone, Debug, serde::Deserialize, serde::Serialize, Default, bincode::Decode, bincode::Encode,
)]
pub struct Block {
  pub head: BlockHeader,
  pub data: Vec<String>,
}

impl BlockHeader {
  pub fn previous_hash(&self) -> &str {
    &self.previous_hash
  }
  pub fn timestamp(&self) -> u64 {
    self.timestamp
  }
  pub fn nonce(&self) -> u32 {
    self.nonce
  }
  pub fn merkle_root(&self) -> &str {
    &self.merkle_root
  }
  pub fn block_hash(&self) -> &str {
    &self.block_hash
  }
}

impl Block {
  pub fn new(head: BlockHeader, data: Vec<String>) -> Self {
    Self { head, data }
  }
  pub fn head(&self) -> &BlockHeader {
    &self.head
  }
  pub fn data(&self) -> &[String] {
    &self.data
  }
}
