#pragma once

#include "Texture.h"
#include "Effects/BaseEffect.h"

#include <d3d11.h>
#include <vector>

class Effect;

using namespace dae;

struct VertexIn;
struct VertexOut;




class Mesh final {
public:
    Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
         std::shared_ptr<Material> material, BaseEffect* effectPtr);

    ~Mesh();

    void Render(ID3D11DeviceContext *deviceContextPtr, const Matrix &worldViewProj) const;

    void SetCameraPos(const Vector3 &pos) const;

    Matrix GetWorldMatrix() const { return m_WorldMatrix; }

    void ToggleNormals();

    void NextSamplingState();

    void SetWorldMatrix(const Matrix &matrix);

private:
    BaseEffect *m_EffectPtr;

    Matrix m_WorldMatrix{};

    ID3D11InputLayout *m_InputLayoutPtr;
    ID3D11Buffer *m_VertexBufferPtr;
    ID3D11Buffer *m_IndexBufferPtr;

    std::vector<VertexIn> m_VerticesIn;
    std::vector<uint32_t> m_Indices;
    UINT m_IndicesCount;

    std::shared_ptr<Material> m_Material{};
};

struct VertexIn {
    Vector3 position{};
    Vector2 uv{};
    Vector3 normal{};
    Vector3 tangent{};
};

struct VertexOut {
    Vector4 position{};
    ColorRGB color{};
    Vector2 uv{};
    Vector3 normal{};
    Vector3 tangent{};
    Vector3 viewDir{};
};

