// file: kb_lib/src/db/types/liquidity_event_kind.rs

//! Liquidity event kind.

/// Normalized liquidity event kind.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum LiquidityEventKind {
    /// Liquidity addition.
    Add,
    /// Liquidity removal.
    Remove,
}

impl LiquidityEventKind {
    /// Converts the event kind to its stable integer representation.
    pub fn to_i16(self) -> i16 {
        match self {
            Self::Add => return 0,
            Self::Remove => return 1,
        }
    }

    /// Restores an event kind from its stable integer representation.
    pub fn from_i16(value: i16) -> Result<Self, crate::Error> {
        match value {
            0 => return Ok(Self::Add),
            1 => return Ok(Self::Remove),
            _ => {
                return Err(crate::Error::Db(format!(
                    "invalid LiquidityEventKind value: {}",
                    value
                )));
            },
        }
    }
}
