/*
    Appellation: records <module>
    Contrib: @FL03
*/
use super::kinds::RecordKind;
use crate::core::identity::Id;
use crate::core::time::Timestamp;

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(
    feature = "serde",
    derive(serde_derive::Deserialize, serde_derive::Serialize),
    serde(rename_all = "snake_case")
)]
pub struct Record {
    pub(crate) id: Id,
    pub(crate) hash: String,
    pub(crate) kind: RecordKind,
    pub(crate) nodes: usize,
    pub(crate) created_at: Timestamp,
}

impl Record {
    pub fn new(hash: String, nodes: usize, kind: RecordKind) -> Self {
        Self {
            id: Id::atomic(),
            hash,
            kind,
            nodes,
            created_at: Timestamp::now_in_millis(),
        }
    }
}
