//! Eval implementations for membership operators

use hamelin_lib::func::defs::{
    NumericRange, NumericRangeInclusive, TimestampRange, TimestampRangeInclusive,
};

use crate::registry::EvalRegistry;
use crate::value::{RangeValue, Value};

/// Register all membership operator eval implementations.
pub fn register(registry: &mut EvalRegistry) {
    // NumericRange: left..right -> Range(left, right)
    registry.register_eval::<NumericRange>(|mut bindings| {
        let left = bindings.take()?;
        let right = bindings.take()?;
        Ok(Value::Range(Box::new(RangeValue {
            lower: Some(left),
            upper: Some(right),
        })))
    });

    // TimestampRange: left..right -> Range(left, right)
    registry.register_eval::<TimestampRange>(|mut bindings| {
        let left = bindings.take()?;
        let right = bindings.take()?;
        Ok(Value::Range(Box::new(RangeValue {
            lower: Some(left),
            upper: Some(right),
        })))
    });

    // NumericRangeInclusive: left..=right -> Range(left, right)
    registry.register_eval::<NumericRangeInclusive>(|mut bindings| {
        let left = bindings.take()?;
        let right = bindings.take()?;
        Ok(Value::Range(Box::new(RangeValue {
            lower: Some(left),
            upper: Some(right),
        })))
    });

    // TimestampRangeInclusive: left..=right -> Range(left, right)
    registry.register_eval::<TimestampRangeInclusive>(|mut bindings| {
        let left = bindings.take()?;
        let right = bindings.take()?;
        Ok(Value::Range(Box::new(RangeValue {
            lower: Some(left),
            upper: Some(right),
        })))
    });

    // No reverse eval for membership operators - they're not invertible
}
