use nautilus_common::command::valid_priority_command::ValidPriorityCommand;
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
use std::time::Instant;

#[derive(Clone, Debug)]
pub struct InstantPriorityCommand<T>
where
    T: Clone + Debug,
{
    pub inner: T,
    pub valid_until: Instant,
    pub priority: u8,
}

impl<T> From<ValidPriorityCommand<T>> for InstantPriorityCommand<T>
where
    T: Clone + Debug,
{
    fn from(value: ValidPriorityCommand<T>) -> Self {
        let valid_until = value.get_valid_until_instant();
        Self {
            inner: value.inner,
            valid_until,
            priority: value.priority,
        }
    }
}

impl<T: Clone + Debug> Deref for InstantPriorityCommand<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl<T: Clone + Debug> DerefMut for InstantPriorityCommand<T> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.inner
    }
}
