/**
 * Copyright (c) 2021 Dominic Msters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#pragma once
#include <dawn/dawn.h>
#include "../display/shader.h"
#include "../display/texture.h"
#include "../display/gui/font.h"

/**
 * Method to load an asset into memory as a raw string.
 * @param assetName Path leading to the asset within the root asset directory.
 * @return Pointer to char array of data from asset, NULL if unsuccesful.
 */
char * assetStringLoad(char *assetName);

/**
 * Platform-centric method to open a file buffer to an asset.
 * @param assetName The asset name to open a buffer for.
 * @return Pointer to a buffer, NULL if unsuccessfuil.
 */
FILE * assetBufferOpen(char *assetName);

/**
 * Closes a previously opened asset buffer.
 * @param buffer Buffer to close.
 * @return True if successful, otherwise false.
 */
bool assetBufferClose(FILE *buffer);

/**
 * Read bytes from buffer.
 * @param buffer The buffer pointing to an asset.
 * @param data Pointer to a ubyte array to buffer data into.
 * @param size Length of the data buffer. Represents how many bytes can be read.
 * @return The count of bytes read. Complete when less than data array size.
 */
int32_t assetBufferRead(FILE *buffer, char *data, int32_t size);

/**
 * Skip to the end of the buffer, useful to find the length of the buffer.
 * @param Buffer The buffer pointing to an asset.
 * @return How many bytes were skipped
 */
int32_t assetBufferEnd(FILE *buffer);

/**
 * Method to skip n bytes in the buffer
 * @param buffer The buffer pointing to an asset.
 * @param n Count of bytes to skip.
 */
void assetBufferSkip(FILE *buffer, int32_t n);

/**
 * Load a shader program from a vertex and fragment shader file.
 * @param shader Shader to load into.
 * @param fileVertex The file path of the vertex shader
 * @param fileFragment The file path of the fragment shader
 */
void assetShaderLoad(shader_t *shader, char *fileVertex, char *fileFragment);

/**
 * Load a texture from a PNG file.
 * @param texture Texture to load the file into.
 * @param fileName The file path of the PNG image.
 */
void assetTextureLoad(texture_t *texture, char *fileName);

/**
 * Load a font from a TTF file.
 * @param font Font to load into.
 * @param assetName Asset name for the TTF font.
 * @param size Size of the font.
 */
void assetFontLoad(font_t *font, char *assetName);