#ifndef ARC_CONSOLE_VIEW_H_
#define ARC_CONSOLE_VIEW_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <wchar.h>
#include "arc/console/key.h"
#include "arc/math/rectangle.h"
#include "arc/std/bool.h"
#include "arc/std/string.h"

/**
 * @brief
*/
typedef struct ARC_ConsoleView ARC_ConsoleView;

/**
 * @brief
*/
typedef struct ARC_ConsoleElement ARC_ConsoleElement;

/**
 * @brief creates ARC_ConsoleView type
 *
 * @param view   ARC_ConsoleView to create
 * @param bounds the bounds of the window, if bounds.w == 0 or bounds.h == 0, bounds will take up the entire screen
*/
void ARC_ConsoleView_Create(ARC_ConsoleView **view, ARC_Rect bounds);

/**
 * @brief destroys ARC_ConsoleView type
 *
 * @param view ARC_ConsoleView to destroy
*/
void ARC_ConsoleView_Destroy(ARC_ConsoleView *view);

/**
 * @brief adds an ARC_ConsoleElement to the ARC_ConsoleView type
 *
 * @note the elements position will be based on the ARC_ConsoleView which might mess up how it looks
 *
 * @param view
 * @param elment
*/
void ARC_ConsoleView_AddElement(ARC_ConsoleView *view, ARC_ConsoleElement *element);

/**
 * @brief
 *
 * @param view
 * @param index
*/
void ARC_ConsoleView_RemoveElement(ARC_ConsoleView *view, uint32_t index);

/**
 * @brief
 *
 * @param view
 * @param index
*/
void ARC_ConsoleView_Clear(ARC_ConsoleView *view);

/**
 * @brief
 *
 * @param view
 * @param character
 * @param pos
*/
void ARC_ConsoleView_RenderCharAt(ARC_ConsoleView *view, char character, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param character
 * @param pos
*/
void ARC_ConsoleView_RenderWCharAt(ARC_ConsoleView *view, wchar_t character, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param key
 * @param pos
*/
void ARC_ConsoleView_RenderKeyAt(ARC_ConsoleView *view, ARC_ConsoleKey key, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param uint32
 * @param pos
*/
void ARC_ConsoleView_RenderUint32At(ARC_ConsoleView *view, uint32_t uint32, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param text
 * @param pos
*/
void ARC_ConsoleView_RenderStringAt(ARC_ConsoleView *view, ARC_String *text, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param text
 * @param pos
*/
void ARC_ConsoleView_RenderCStringWithStrlenAt(ARC_ConsoleView *view, char *cstr, ARC_Point pos);

/**
 * @brief
 *
 * @param view
 * @param bounds
*/
void ARC_ConsoleView_RenderRect(ARC_ConsoleView *view, ARC_Rect bounds);

/**
 * @brief
 *
 * @param view
*/
void ARC_ConsoleView_RenderElements(ARC_ConsoleView *view);

/**
 * @brief gets the bounds of an ARC_ConsoleView
 *
 * @param view ARC_ConsoleView to get bounds from
 *
 * @return the bounds of the ARC_ConsoleView
*/
ARC_Rect ARC_ConsoleView_GetBounds(ARC_ConsoleView *view);

/**
 * @brief adds an ARC_ConsoleElement to the ARC_ConsoleView type
 *
 * @note the elements position will be based on the ARC_ConsoleView which might mess up how it looks
 *
 * @param view
 * @param index
*/
ARC_ConsoleElement *ARC_ConsoleView_GetElement(ARC_ConsoleView *view, uint32_t index);

/**
 * @brief gets a char from the view
 *
 * @note use ARC_ConsoleView_GetInt32At if you want to check for direction key or special character input
 *
 * @param view the ARC_ConsoleView to get the char from
*/
char ARC_ConsoleView_GetChar(ARC_ConsoleView *view);

/**
 * @brief gets a char from the view at a position
 *
 * @note use ARC_ConsoleView_GetInt32At if you want to check for direction key or special character input
 *
 * @param view the ARC_ConsoleView to get the char from
 * @param pos  the positiion to get the char at
*/
char ARC_ConsoleView_GetCharAt(ARC_ConsoleView *view, ARC_Point pos);

/**
 * @brief gets a console key from the view at a position
 *
 * @note you most likely do not want to use this function outside of a backend as ARC_ConsoleKey is defined within the console backend
 *
 * @param view the ARC_ConsoleView to get the console key from
 * @param pos  the positiion to get the console key at
 *
 * @return a console key
*/
ARC_ConsoleKey ARC_ConsoleView_GetConsoleKeyAt(ARC_ConsoleView *view, ARC_Point pos);

/**
 * @brief gets and creates a console key from the view at a position
 *
 * @note the given ARC_ConsoleKey needs to be destroyed
 * @note use ARC_ConsoleView_GetConsoleKeyAt if you want to check for keyboard or special character input
 *
 * @param view the ARC_ConsoleView to get the console key from
 * @param pos  the positiion to get the console key at
 *
 * @return a console key
*/
ARC_ConsoleKey *ARC_ConsoleView_GetCreateConsoleKeyAt(ARC_ConsoleView *view, ARC_Point pos);

/**
 * @brief callback to check char being read in and override functionality
 *
 * @note this function is used for pressing arrow keys but can be used for anything
 *
 * @param key          the current key being read in
 * @param inputCStr    the cstring that holds the current contents of the input
 * @param inputSize    the size of the current contents of the input string
 * @param maxInputSize the max size inputCStr can store
 * @param userdata     data that a user can pass to use within this function
*/
typedef ARC_Bool (* ARC_ConsoleView_OverrideCharInputFn)(ARC_ConsoleKey *key, char *inputCStr, uint32_t *inputSize, uint32_t maxInputSize, void *userdata);

/**
 * @brief gets a ARC_String from the view at a position
 *
 * @param view                the ARC_ConsoleView to get the string from
 * @param pos                 the positiion to get the string at
 * @param overrideCharInputFn a function to allow overriding what happens when inputing chars, can be NULL
 * @param userdata            data that a user can pass to use within the overrideCharInputFn
*/
ARC_String *ARC_ConsoleView_GetStringInput(ARC_ConsoleView *view, ARC_Point pos, ARC_ConsoleView_OverrideCharInputFn *overrideCharInputFn, void *userdata);

/**
 * @brief mouse options
*/
#define ARC_CONSOLE_VIEW_CURSOR_HIDDEN  0x00
#define ARC_CONSOLE_VIEW_CURSOR_VISIBLE 0x01

/**
 * @brief sets a visibility of the cursor with an ARC_ConsoleView
 *
 * @param view       ARC_ConsoleView to set mouse visibility
 * @param visibility the visibility to set
*/
void ARC_ConsoleView_SetCursorVisibility(ARC_ConsoleView *view, uint8_t visibility);

/**
 * @brief border options
*/
#define ARC_CONSOLE_VIEW_BORDER_NONE           0x00
#define ARC_CONSOLE_VIEW_BORDER_DEFAULT        0x01

/**
 * @brief sets a border on the ARC_ConsoleView
 *
 * @param view   ARC_ConsoleView to set border to
 * @param border The border to set
*/
void ARC_ConsoleView_SetBorder(ARC_ConsoleView *view, uint32_t border);

/**
 * @brief border options
*/
#define ARC_CONSOLE_VIEW_ATTRIBUTE_NONE    0x00
#define ARC_CONSOLE_VIEW_ATTRIBUTE_REVERSE 0x01

/**
 * @brief sets a border on the ARC_ConsoleView
 *
 * @param view   ARC_ConsoleView to set border to
 * @param border The border to set
*/
void ARC_ConsoleView_SetAttribute(ARC_ConsoleView *view, uint32_t attribute);

#ifdef __cplusplus
}
#endif

#endif //!ARC_CONSOLE_VIEW_H_
