use std::collections::HashMap;
use std::rc::Rc;

use crate::entity::EntityHandle;
use crate::mesh::Mesh;
use crate::render::{DrawCall, Pipeline};

pub type DrawHandle = usize;

struct DrawEntry
{
    mesh: Rc<Mesh>,
    entity: EntityHandle,
    pipeline: Pipeline,
}

pub struct DrawManager
{
    entries: HashMap<DrawHandle, DrawEntry>,
    next_handle: DrawHandle,
}

impl DrawManager
{
    pub fn new() -> Self
    {
        Self {
            entries: HashMap::new(),
            next_handle: 0,
        }
    }

    pub fn draw_mesh_internal(
        &mut self,
        mesh: Rc<Mesh>,
        entity: EntityHandle,
        pipeline: Pipeline,
    ) -> DrawHandle
    {
        let handle = self.next_handle;
        self.next_handle += 1;

        self.entries.insert(
            handle,
            DrawEntry {
                mesh,
                entity,
                pipeline,
            },
        );

        handle
    }

    pub fn clear_mesh_internal(&mut self, handle: DrawHandle)
    {
        self.entries.remove(&handle);
    }

    pub fn collect_draw_calls(&self) -> Vec<DrawCall>
    {
        vec![]
    }

    pub fn draw_mesh(_mesh: Rc<Mesh>, _entity: EntityHandle, _pipeline: Pipeline) -> DrawHandle
    {
        0
    }

    pub fn clear_mesh(_handle: DrawHandle) {}
}
