use crate::targeting::NumberTargetingOperator;

pub(super) struct NumberCondition<T: PartialEq + PartialOrd> {
    value: T,
    match_type: NumberTargetingOperator,
}

impl<T: PartialEq + PartialOrd> NumberCondition<T> {
    pub fn new(value: T, match_type: String) -> Option<Self> {
        Some(Self {
            value,
            match_type: NumberTargetingOperator::from_str(&match_type)?,
        })
    }

    pub fn check(&self, value: T) -> bool {
        match self.match_type {
            NumberTargetingOperator::Equal => value == self.value,
            NumberTargetingOperator::Greater => value > self.value,
            NumberTargetingOperator::Lower => value < self.value,
        }
    }
}
