#pragma once
#include <thread>
#include <vector>

#include "fps_class.h"
#include "object.h"
#include <intrin.h> // Pour __cpuid
#include <dxgi.h>   // Pour DXGI
#include <mutex>
#pragma comment(lib, "dxgi.lib")

class stats
{
public:

    stats();
    ~stats();

    bool initialize(application_class* app);
    void update_geometric_stats();
    void update_visible_count();
    void update_display_stats();

    int get_total_vertex_count() const;
    int get_total_triangle_count() const;
    int get_visible_triangle_count() const;

    int get_current_fps() const { return current_fps_; };
    int get_min_fps() const { return min_fps_; };
    int get_max_fps() const { return max_fps_; };
    float get_frame_time() const { return current_frame_time_;};
    int get_draw_calls() const { return drawcalls_; };
    
    void increment_draw_call_count() { drawcalls_++; };
    void reset_draw_call_count() { drawcalls_ = 0; };

    std::string get_cpu_name();
    std::string get_gpu_driver_version(ID3D11Device* device);

    std::shared_ptr<int>& get_vertex_count_ptr() { return total_vertex_count_; }
    std::shared_ptr<int>& get_triangle_count_ptr() { return total_triangle_count_; }
    

private:
    std::thread update_display_thread_;
    
    fps_class* fps_;
    int drawcalls_;
    application_class* app_;

    std::vector<object*> object_vec_;
    std::vector<object*> cubes_vec_;
    std::vector<object*> terrain_chunk_vec_;

    std::shared_ptr<int> total_vertex_count_;
    std::shared_ptr<int> total_triangle_count_;
    
    int visible_triangle_count_ = 0;
    int current_fps_ = 0;
    int min_fps_ = 0;
    int max_fps_ = 0;
    float current_frame_time_ = 0.0f;
    
};
