use crate::*;

#[derive(Clone, Hash, PartialEq, Eq, Debug)]
/// Generic value.
pub enum Value {
    Int(i64),
    String(LString),
    Binary(LVec<u8>),
    List(LVec<Value>),
    Enum(i64, LBox<Value>),
    VarVal(u64, u64),
    IList(LVec<i64>),
}

impl Value {
    // Get mut reference to List LVec ( Value must be List )
    pub fn list(&mut self) -> &mut LVec<Value> {
        match self {
            Value::List(list) => list,
            _ => panic!(),
        }
    }

    // Get mut reference to IList LVec ( Value must be IList )
    pub fn ilist(&mut self) -> &mut LVec<i64> {
        match self {
            Value::IList(list) => list,
            _ => panic!(),
        }
    }

    // Get reference to LString ( Value must be String )
    pub fn string(&self) -> &LString {
        match self {
            Value::String(s) => s,
            _ => panic!(),
        }
    }

    pub fn int(&self) -> i64 {
        match self {
            Value::Int(x) => *x,
            _ => panic!(),
        }
    }
}

#[test]
fn test_value() {
    /*
        use pstd::veca;
        let v1 = Value::List(veca![
            Value::String(LString::from("George Barwood")),
            Value::String(LString::from("george.barwood@gmail.com")),
            Value::String(LString::from("33 Sandpipe Close, GL2 4LZ")),
            Value::Int(-47),
            Value::Int(99),
            Value::VarVal(100, 20),
            Value::IList(veca![1, 2, 3, 4]),
        ]);
        let bytes = v1.to_bytes();
        println!("len={} bytes={:?}", bytes.len(), bytes);

        let v2 = Value::from_bytes(&bytes);
        println!("v2={:?}", v2);
    */
}
