use freecs::Entity;

pub enum WorldCommand {
    SpawnEntity { mask: u64 },
    DespawnEntity { entity: Entity },
    AddComponents { entity: Entity, mask: u64 },
    RemoveComponents { entity: Entity, mask: u64 },
}

#[derive(Default)]
pub struct CommandQueue {
    pub commands: Vec<WorldCommand>,
}

impl CommandQueue {
    pub fn queue_spawn(&mut self, mask: u64) {
        self.commands.push(WorldCommand::SpawnEntity { mask });
    }

    pub fn queue_despawn(&mut self, entity: Entity) {
        self.commands.push(WorldCommand::DespawnEntity { entity });
    }

    pub fn queue_add_components(&mut self, entity: Entity, mask: u64) {
        self.commands
            .push(WorldCommand::AddComponents { entity, mask });
    }

    pub fn queue_remove_components(&mut self, entity: Entity, mask: u64) {
        self.commands
            .push(WorldCommand::RemoveComponents { entity, mask });
    }

    pub fn drain(&mut self) -> Vec<WorldCommand> {
        std::mem::take(&mut self.commands)
    }
}
