use serde::{Deserialize, Serialize};
use tritools::time::unix_epoch_timestamp;
use super::id::Id;

/// All of the items which support reactions.
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum AssetType {
    #[serde(alias = "post")]
    Post,
    #[serde(alias = "question")]
    Question,
    #[serde(alias = "group")]
    Group,
    #[serde(alias = "user")]
    User,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Reaction {
    pub id: Id,
    pub created: u128,
    pub owner: Id,
    pub asset: Id,
    pub asset_type: AssetType,
    pub is_like: bool,
}

impl Reaction {
    /// Create a new [`Reaction`].
    pub fn new(owner: Id, asset: Id, asset_type: AssetType, is_like: bool) -> Self {
        Self {
            id: Id::new(),
            created: unix_epoch_timestamp(),
            owner,
            asset,
            asset_type,
            is_like,
        }
    }
}
