#pragma once

#include <wrl.h>
#include <directxmath.h>
#include <d3d12.h>

#include <memory>
#include <vector>

class SceneModel;
class DrawingContext;

class DirectXMesh
{
public:
    DirectXMesh(SceneModel* model);

    const D3D12_VERTEX_BUFFER_VIEW& getVertBufferView() const;

    const D3D12_INDEX_BUFFER_VIEW& getIndexBufferView() const;

    SceneModel* getModel() const;

    void update(DrawingContext* context, ID3D12Device* device);

private:
    struct Vertex
    {
        DirectX::XMFLOAT3 position;
        DirectX::XMFLOAT4 color;
    };

    void createD3dVertexBuffer(ID3D12Device* device);
    void uploadVertexBuffer(unsigned char* pBuffer) const;

    void createD3dIndexBuffer(ID3D12Device* device);
    void uploadIndexBuffer(unsigned char* pBuffer) const;

    SceneModel* mModel{ nullptr };

    std::vector<Vertex> mVertexBuffer;
    Microsoft::WRL::ComPtr<ID3D12Resource> mD3dVertexBuffer;
    D3D12_VERTEX_BUFFER_VIEW mVertexBufferView{};

    std::vector<unsigned> mIndexBuffer;
    Microsoft::WRL::ComPtr<ID3D12Resource> mD3dIndexBuffer;
    D3D12_INDEX_BUFFER_VIEW mIndexBufferView{};
};