use pine_core::{Bar, PineOutput};
use pine_interpreter::Value;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
pub fn register<O: PineOutput>(bar: &Bar) -> Value<O> {
let members: HashMap<String, Value<O>> = [
("isfirst", bar.is_first),
("islast", bar.is_last),
("isnew", bar.is_new),
("isconfirmed", bar.is_confirmed),
("ishistory", bar.is_history),
("isrealtime", bar.is_realtime),
("islastconfirmedhistory", bar.is_last_confirmed_history),
]
.into_iter()
.map(|(name, flag)| (name.to_string(), Value::Bool(flag)))
.collect();
Value::Object {
type_name: "barstate".to_string(),
fields: Rc::new(RefCell::new(members)),
call: None,
}
}