use super::*;

pub type MemoryLayout = Vec<Layout>;

pub struct DefaultLayout {
}

impl DefaultLayout {
    pub fn new(parent: &CDDesc) -> Vec<Layout> {
        let mut layout = Vec::new();
        
        layout.push(Layout::SystemArea(parent.system_area.clone()));
        layout.push(Layout::PVD(parent.pvd.clone()));
        layout.push(Layout::PathTables(parent.root.clone(), parent.path_table.clone()));

        Self::add_dir_and_subdir(&mut layout, parent.root.clone());
        layout
    }

    fn add_dir_and_subdir(layout: &mut Vec<Layout>, dir: SharedPtr<Directory>) {
        layout.push(Layout::Directory(dir.clone()));
        
        let dir = dir.borrow();
        for file in dir.files.iter() {
            layout.push(Layout::File(file.clone()));
        }

        for dir in dir.dirs.iter() {
            Self::add_dir_and_subdir(layout, dir.clone());
        }
    }    
}

pub enum Layout {
    SystemArea(SharedPtr<SystemArea>),
    PVD(SharedPtr<PrimaryVolumeDescriptor>),
    PathTables(SharedPtr<Directory>, SharedPtr<PathTable>),
    Directory(SharedPtr<Directory>),
    File(SharedPtr<File>)
}           

