#include "include.h"

#include <string>

Napi::Array current_gpu_status(const Napi::CallbackInfo& info){
    Napi::Env env = info.Env();
    Napi::Array myarray=Napi::Array::New(env);
    std::vector<Hardware> hardwares=computer->getHardware();
    for (int i=0;i<hardwares.size();i++){
        if(hardwares[i].getHardwareType()==HardwareType::GpuNvidia
            || hardwares[i].getHardwareType()==HardwareType::GpuAmd
            || hardwares[i].getHardwareType()==HardwareType::GpuIntel){
            Napi::Object object=Napi::Object::New(env);
            object.Set<Napi::String>("name", Napi::String::New(env, hardwares[i].Name()));
            for(Sensor sen:hardwares[i].getSensors()){
                if(sen.getType()==SensorType::Power){
                    object.Set<float>("power", sen.getValue()); 
                }
                else if(sen.getType()==SensorType::Load && (strcmp(sen.getName(),"GPU Core")==0)){
                    object.Set<float>("load", sen.getValue()); 
                }
                else if(sen.getType()==SensorType::Clock){
                    object.Set<float>("freq", sen.getValue()); 
                }
            }
            myarray.Set(i,object);
        }
    }
    return myarray;   
}