use embedded_hal::digital::PinState;
use nautilus_common::command::set_pin::SetPin;
use nautilus_common::command::valid_priority_command::ValidPriorityCommand;
use std::time::Instant;

pub trait PinDevice {
    fn set_pin(&self, pin: u8, value: PinState, valid_until: Instant, priority: u8);

    fn new_set_pin_callback<'a>(&self) -> impl Fn(ValidPriorityCommand<SetPin>) + 'a
    where
        Self: Sized + Clone + 'a,
    {
        let this = self.clone();
        move |cmd| {
            this.set_pin(
                cmd.pin,
                cmd.value.into(),
                cmd.get_valid_until_instant(),
                cmd.priority,
            );
        }
    }
}

pub trait Pin {
    fn set(&mut self, value: PinState, valid_until: Instant, priority: u8);
}
