use glam::Vec3;

use crate::bundles::Bundle;
use crate::components::CameraComponent;
use crate::entity::EntityHandle;
use crate::render;
use crate::world::{Transform, World};

pub struct CameraBundle
{
    pub position: Vec3,
}

impl Bundle for CameraBundle
{
    fn spawn(self, world: &mut World) -> Result<EntityHandle, String>
    {
        let camera_entity = world.spawn();
        let camera_component = CameraComponent::new(render::aspect_ratio());
        let transform = Transform::from_position(self.position);
        world.cameras.insert(camera_entity, camera_component);
        world.transforms.insert(camera_entity, transform);
        world.names.insert(camera_entity, "Camera".to_string());
        Ok(camera_entity)
    }
}
