use alloc::vec::Vec;

use core::slice;
use core::ops::Deref;

use specs::Entity;


pub struct TransformGuide {
    sorted: Vec<Entity>,
}

impl TransformGuide {
    #[inline(always)]
    pub fn new() -> Self {
        TransformGuide {
            sorted: Vec::new(),
        }
    }

    #[inline(always)]
    pub(crate) fn set(&mut self, sorted: Vec<Entity>) {
        self.sorted = sorted;
    }

    #[inline(always)]
    pub fn as_slice(&self) -> &[Entity] {
        &*self.sorted
    }
    #[inline(always)]
    pub(crate) fn as_slice_mut(&mut self) -> &mut [Entity] {
        &mut *self.sorted
    }
}

impl Deref for TransformGuide {
    type Target = Vec<Entity>;

    #[inline(always)]
    fn deref(&self) -> &Self::Target { &self.sorted }
}

impl<'a> IntoIterator for &'a TransformGuide {
    type Item = &'a Entity;
    type IntoIter = slice::Iter<'a, Entity>;

    fn into_iter(self) -> Self::IntoIter {
        self.as_slice().into_iter()
    }
}
