#ifndef _H_TEXTURE_H
#define _H_TEXTURE_H

#include <vector>
#include <thirdparty/glad/glad.h>
#include <SDL_image.h>

struct SDL_Surface;

class Texture
{
public:
	Texture() {}
	bool loadTexture(const char* imagePath);

	void bind();

	const int getWidth()  const { return textureWidth; }
	const int getHeight() const { return textureHeight; }

	~Texture();
private:
	unsigned ID = 0;
	int textureWidth = 0;
	int textureHeight = 0;
};

class TextureArray
{
private:
	struct TextureData {
		int width, height;
	};
public:
	TextureArray() : numOfLayers(0) {}
	/* We are going to assume each texture atlas is a square (512x512, 756x756 ... etc) */
	bool loadTextures(std::vector<const char*> imagePaths);

	void bind();

	TextureData operator[](const size_t index) {
		try
		{
			return textures.at(index);
		}
		catch (std::exception&)
		{ 
			return { 0, 0 };
		}
	}

	const int getWidth()  const { return canvasWidth; }
	const int getHeight() const { return canvasHeight; }

	~TextureArray();

private:
	bool adjustCanvasSizes(std::vector<SDL_Surface*>& surfaces);

	size_t numOfLayers;
	unsigned ID = 0;
	std::vector<TextureData> textures;
	int canvasWidth = 0;
	int canvasHeight = 0;
};

#endif
