#include "Renderable.hpp"

#include <typeinfo>
#include "MeshContainer.hpp"
#include "RectBase.hpp"
#include "elements/Transformable.hpp"

namespace TSE
{
    Renderable::Renderable() = default;

    Renderable::Renderable(Material* mat)
    {
        SetMaterial(mat);
    }

    void Renderable::SetMaterial(Material* mat) {
        material = mat;
    }

    Material* Renderable::GetMaterial() {
        return material;
    }

    Mesh* Renderable::GetMeshContainer() const {
        if(baseObject->HasBehaviourScript(MESH_CONTAINER))
            return dynamic_cast<MeshContainer*>(baseObject->GetBehaviourScript(MESH_CONTAINER))->GetMesh();
        if(baseObject->HasBehaviourScript(RECT_BASE))
            return dynamic_cast<RectBase*>(baseObject->GetBehaviourScript(RECT_BASE))->GetMesh();
        return nullptr;
    }

    const Vector3* Renderable::GetVertices() const {
        auto* container = GetMeshContainer();
        return container ? container->vertecies.data() : nullptr;
    }

    const Vector2* Renderable::GetUVs() const {
        auto* container = GetMeshContainer();
        return container ? container->uvs.data() : nullptr;
    }
    const std::vector<ushort> Renderable::GetIndices() const
    {
        auto* container = GetMeshContainer();
        return container ? container->indecies : std::vector<unsigned short>();
    }
    size_t Renderable::GetVertexCount() const
    {
        auto* container = GetMeshContainer();
        return container ? container->VerteciesCount() : 0;
    }
} // namespace TSE
