use super::number::Number;
use super::r#enum::{CoerceEnum,Enums};

#[expect(dead_code)]
#[derive(Clone)]
pub struct TweenInfo{
	time:f64,
	easing_style:rbx_types::Enum,
	easing_direction:rbx_types::Enum,
	repeat_count:u32,
	reverses:bool,
	delay_time:f64,
}

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(|_,(time,easing_style,easing_direction,repeat_count,reverses,delay_time):(Option<Number>,Option<CoerceEnum>,Option<CoerceEnum>,Option<u32>,Option<bool>,Option<Number>)|{
			Ok(TweenInfo{
				time:time.map_or(1.0,Number::to_f64),
				easing_style:match easing_style{
					// Enum.EasingStyle.Quad
					None=>rbx_types::Enum::from_u32(3),
					Some(e)=>e.coerce_to(Enums.get("EasingStyle").unwrap())?.into(),
				},
				easing_direction:match easing_direction{
					// Enum.EasingDirection.Out
					None=>rbx_types::Enum::from_u32(1),
					Some(e)=>e.coerce_to(Enums.get("EasingDirection").unwrap())?.into(),
				},
				repeat_count:repeat_count.unwrap_or(0),
				reverses:reverses.unwrap_or(false),
				delay_time:delay_time.map_or(0.0,Number::to_f64),
			})
		})?
	)?;

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

	Ok(())
}

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