// Copyright 2024 SquareBlock Inc. All Rights Reserved.
// Author: tianlei.richard@qq.com (tianlei.richard)

#pragma once

#include <array>
#include <memory>
#include <unordered_map>

#include "common.h"
#include "phone_material.h"
#include "triangle.h"

class Mesh {
public:
  Mesh(const std::vector<Vertex> &vertices,
       const std::vector<std::array<size_t, 3>> &indices,
       const std::shared_ptr<PhoneMaterial> &phone_material);

  static std::vector<Mesh> load_mesh(
      const std::string &obj_path,
      const std::unordered_map<Texture::TextureType, std::string> textures);

public:
  std::vector<Vertex> &get_vertices();

  std::vector<Vertex>::size_type get_vertex_size() const;

  const decltype(Vertex::texture_coordinate) &
  get_texture_coordinate(const unsigned int index) const;

  Point3d get_normal_vector(const unsigned int index) const;

  std::vector<Triangle> get_primitives() const;
  Triangle get_primitive(const size_t index) const;

  const std::shared_ptr<PhoneMaterial> &get_material() const;

private:
  std::vector<Vertex> vertices_;
  std::vector<std::array<size_t, 3>> indices_;

  std::shared_ptr<PhoneMaterial> material_;
};
