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

#pragma once

#include <memory>
#include <unordered_map>

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

class Mesh {
public:
  Mesh(const std::vector<std::shared_ptr<Vertex>> &vertices,
       const std::vector<Triangle> &primitives,
       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<std::shared_ptr<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;

  const std::vector<Triangle> &get_primitives() const;
  std::vector<Triangle> &get_primitives();

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

private:
  std::vector<std::shared_ptr<Vertex>> vertices_;
  std::vector<Triangle> primitives_;

  std::shared_ptr<PhoneMaterial> material_;
};
