use std::{
    io,
    os::{
        fd::{AsRawFd, RawFd},
        yggdrasil::io::timer::TimerFd as YggTimerFd,
    },
    time::Duration,
};

use crate::sys::TimerFd;

pub struct TimerFdImpl(YggTimerFd);

impl TimerFd for TimerFdImpl {
    fn new() -> std::io::Result<Self> {
        YggTimerFd::new(false, true).map(Self)
    }

    fn start(&mut self, timeout: Duration) -> io::Result<()> {
        self.0.start(timeout)
    }

    fn is_expired(&mut self) -> io::Result<bool> {
        self.0.is_expired()
    }
}

impl AsRawFd for TimerFdImpl {
    fn as_raw_fd(&self) -> RawFd {
        self.0.as_raw_fd()
    }
}
