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

//! Pool status.

/// Normalized pool status.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum PoolStatus {
    /// Unknown status.
    Unknown,
    /// Pool detected but not yet fully active.
    Pending,
    /// Pool active.
    Active,
    /// Pool inactive.
    Inactive,
    /// Pool closed.
    Closed,
}

impl PoolStatus {
    /// Converts the status to its stable integer representation.
    pub fn to_i16(self) -> i16 {
        match self {
            Self::Unknown => return 0,
            Self::Pending => return 1,
            Self::Active => return 2,
            Self::Inactive => return 3,
            Self::Closed => return 4,
        }
    }

    /// Restores a status 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::Pending),
            2 => return Ok(Self::Active),
            3 => return Ok(Self::Inactive),
            4 => return Ok(Self::Closed),
            _ => return Err(crate::Error::Db(format!("invalid PoolStatus value: {}", value))),
        }
    }
}
