use super::number::Number;

#[derive(Clone)]
pub struct NumberRange(rbx_types::NumberRange);
impl NumberRange{
	pub const fn new(min:f32,max:f32)->Self{
		Self(rbx_types::NumberRange{min,max})
	}
}
impl From<NumberRange> for rbx_types::NumberRange{
	fn from(NumberRange(value):NumberRange)->rbx_types::NumberRange{
		value
	}
}

pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
	let table=lua.create_table()?;

	table.raw_set("new",
		lua.create_function(|_,(min,max):(Number,Option<Number>)|{
			Ok(match max{
				Some(max)=>NumberRange::new(min.into(),max.into()),
				None=>NumberRange::new(min.into(),min.into()),
			})
		})?
	)?;

	globals.set("NumberRange",table)?;

	Ok(())
}

impl mlua::UserData for NumberRange{}
type_from_lua_userdata_clone!(NumberRange);
