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

//! Pool kind.

/// Normalized pool kind.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum PoolKind {
    /// Unknown pool kind.
    Unknown,
    /// Constant-product AMM.
    Amm,
    /// Concentrated liquidity market maker.
    Clmm,
    /// Bonding curve pool.
    BondingCurve,
    /// Order book market.
    OrderBook,
}

impl PoolKind {
    /// Converts the kind to its stable integer representation.
    pub fn to_i16(self) -> i16 {
        match self {
            Self::Unknown => return 0,
            Self::Amm => return 1,
            Self::Clmm => return 2,
            Self::BondingCurve => return 3,
            Self::OrderBook => return 4,
        }
    }

    /// Restores a kind from its stable integer representation.
    pub fn from_i16(value: i16) -> Result<Self, crate::Error> {
        match value {
            0 => return Ok(Self::Unknown),
            1 => return Ok(Self::Amm),
            2 => return Ok(Self::Clmm),
            3 => return Ok(Self::BondingCurve),
            4 => return Ok(Self::OrderBook),
            _ => return Err(crate::Error::Db(format!("invalid PoolKind value: {}", value))),
        }
    }
}
