#ifndef RNGLCONTEXTNATIVE_H
#define RNGLCONTEXTNATIVE_H

#include <unordered_map>
#include <mutex>
#include <string>
#include <memory>
#include <functional>
#include "napi/native_api.h"
#include "GLShaderData/GLShaderData.h"
#include "GLFBO/GLFBO.h"

class RNGLContext {
public:
    RNGLContext();
    ~RNGLContext();

    static napi_value AddShader(napi_env env, napi_callback_info info);
    static napi_value RemoveShader(napi_env env, napi_callback_info info);
    static void OH_ShaderCallback(napi_env env, napi_value jsCallback, void *context, void *data);
    
    void addShader(int id, const std::string& name, const std::string& frag);
    void removeShader(int id);
    void shaderFailedToCompile(int id, const std::string& error);
    void shaderSucceedToCompile(int id, const std::unordered_map<std::string, int>& uniformTypes);
    
    std::shared_ptr<GLShaderData> GetShaderData(int id);

    static std::string glTypeString(int type);

private:
    static const std::string STATIC_VERT;
    std::unordered_map<int, std::shared_ptr<GLShaderData>> shaders;
    std::unordered_map<int, std::shared_ptr<GLFBO>> fbos;
    std::unordered_map<int, std::function<void(const std::string&)>> onCompileCallbacks;
    std::mutex mtx;
};

#endif