use std::rc::Rc;

use super::{Environment, Node, NodeEnum, Precedence};

#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct NodeRef {
    value: Rc<NodeEnum>,
}

impl Node for NodeRef {
    fn evaluate(&self, env: &mut Environment) -> Result<Rc<NodeEnum>, String> {
        self.value.evaluate(env)
    }

    fn as_string(&self, env: Option<&Environment>) -> String {
        self.value.as_string(env)
    }

    fn precedence(&self) -> Precedence {
        self.value.precedence()
    }
}

impl NodeRef {
    pub fn new(value: &Rc<NodeEnum>) -> Self {
        Self {
            value: value.clone(),
        }
    }
}
