use super::integer::Time;

#[binrw::binrw]
#[brw(little)]
pub struct TimedPhysicsInstruction{
	pub time:Time,
	pub instruction:super::physics::PhysicsInputInstruction,
}

impl TryInto<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
	type Error=super::integer::RatioError;
	fn try_into(self)->Result<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,Self::Error>{
		Ok(strafesnet_common::instruction::TimedInstruction{
			time:strafesnet_common::integer::Time::raw(self.time),
			instruction:self.instruction.try_into()?,
		})
	}
}
impl TryFrom<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
	type Error=super::physics::PhysicsInputInstructionError;
	fn try_from(value:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<Self,Self::Error>{
		Ok(Self{
			time:value.time.get(),
			instruction:value.instruction.try_into()?,
		})
	}
}