use crate::ffi::OsString;
use crate::fmt;
use crate::mem::size_of;
use crate::str::FromStr;
use crate::sys::yggdrasil::util::KStringList;

#[allow(dead_code)]
#[derive(Clone, Copy)]
pub struct Args {
    list: KStringList,
    index: usize,
}

pub fn args() -> Args {
    Args { list: unsafe { KStringList::new(super::ARGS) }, index: 0 }
}

impl fmt::Debug for Args {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        todo!()
    }
}

impl Iterator for Args {
    type Item = OsString;

    fn next(&mut self) -> Option<Self::Item> {
        if self.index == self.list.len() {
            return None;
        }

        let str = self.list.get(self.index);
        self.index += 1;

        let os_str = OsString::from_str(str).unwrap();

        Some(os_str)
    }
}

impl ExactSizeIterator for Args {
    fn len(&self) -> usize {
        self.list.len()
    }
}

impl DoubleEndedIterator for Args {
    fn next_back(&mut self) -> Option<Self::Item> {
        todo!()
    }
}
