#pragma once

#include <vector>

#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>

#include <mesh.hpp>

namespace gb
{
class Object
{
private:
    using mesh_list_t = std::vector<Mesh>;
public:
    explicit Object(
            const mesh_list_t& meshes,
            const glm::vec3& pos = {0.f, 0.f, 0.f},
            const glm::vec3& scale = {1.f, 1.f, 1.f},
            const glm::vec3& rotate_axis = {0.f, 0.f, 1.f},
            float rotate_angle = 0.f
            );

    explicit Object(
            mesh_list_t&& meshes,
            const glm::vec3& pos = {0.f, 0.f, 0.f},
            const glm::vec3& scale = {1.f, 1.f, 1.f},
            const glm::vec3& rotate_axis = {0.f, 0.f, 1.f},
            float rotate_angle = 0.f
            );

    template <typename Framebuffer, typename Camera>
    void draw(Framebuffer& fb, const Camera& camera) const
    {
        for (const auto& mesh : m_meshes)
        {
            auto c_mesh = mesh.apply(camera.view_mat() * m_model_mat);
            draw_mesh(fb, c_mesh);
        }
    }

private:
    void calc_model_mat(void);

private:
    mesh_list_t m_meshes;

    glm::vec3 m_pos;
    float m_rotate_angle;
    glm::vec3 m_rotate_axis;
    glm::vec3 m_scale;

    glm::mat4 m_model_mat;
};
} // namespace gb
