#ifndef IZ_CONFIG_H
#define IZ_CONFIG_H

#include <stdlib.h>
#include <string.h>
#include <minIni.h>
#include "../common/IZ_common.h"

typedef enum {
	IZ_CONFIG_TYPE_VOID,
	IZ_CONFIG_TYPE_STRING,
	IZ_CONFIG_TYPE_U8,
	IZ_CONFIG_TYPE_U16,
	IZ_CONFIG_TYPE_I32,
	IZ_CONFIG_TYPE_GUID,
} IZ_ConfigType;

typedef struct {
	void* serialize;
	void* deserialize;
} IZ_ConfigSerializerPair;

typedef struct {
	IZ_ConfigType type;
	size_t dest_size;
	const char* section;
	const char* key;
	const char* cmdline_option;
	const void* default_value;
	void* validator;
	IZ_ConfigSerializerPair transformer;
	void* dest;
} IZ_ConfigItem;

void IZ_ConfigGetDefaultPath(const char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*);

typedef enum {
	IZ_CONFIG_INITIALIZE_RESULT_ERROR = -1,
	IZ_CONFIG_INITIALIZE_RESULT_OK,
	IZ_CONFIG_INITIALIZE_RESULT_WARNING
} IZ_ConfigInitializeResult;

IZ_ConfigInitializeResult IZ_ConfigInitialize(IZ_ConfigItem[], const char*, u8, const char*[]);

typedef i64 IZ_ConfigSaveResult;

IZ_ConfigSaveResult IZ_ConfigSave(IZ_ConfigItem[], const char*);

#define IZ_CONFIG_ITEM_NULL (IZ_ConfigItem) { \
	IZ_CONFIG_TYPE_VOID, \
	0, \
	NULL, \
	NULL, \
	NULL, \
	NULL, \
	NULL, \
	{ \
		.serialize = NULL, \
		.deserialize = NULL, \
	}, \
	NULL, \
}

#endif
