#ifndef OPENGL_SHADER_HPP
#define OPENGL_SHADER_HPP

#include "../renderer/shader.hpp"
#include <sys/types.h>
#include <string>
#include <glad/glad.h>
#include <unordered_map>

namespace OpenEngine {
    class OpenGLShader : public Shader
    {
        public:
            OpenGLShader(const std::string& shader_path);
            OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& frament_src);
            virtual ~OpenGLShader() = default;

            virtual const std::string& GetName() const override { return name; };

            // activate the shader
            virtual void Bind() const override;
            virtual void Unbind() const override;

            // utility uniform functions
            virtual void SetBool(const std::string &name, bool value) const;
            virtual void SetInt(const std::string &name, int value) const;
            virtual void SetFloat(const std::string &name, float value) const;
            virtual void SetMat4(const std::string &name, const glm::mat4& value) const;
            virtual void SetVec3(const std::string &name, const glm::vec3& value) const;


        private:
            std::string ReadFile(const std::string& shader_path);
            std::unordered_map<GLenum, std::string> PreProcess(const std::string& shader_source);
            void Compile(const std::unordered_map<GLenum, std::string> sources);
            
            void CheckCompileErrors(unsigned int shader, const std::string& type);

            std::string name;

            u_int32_t id;
    };
}

#endif // OPENGL_SHADER_HPP
