#ifndef GLOBAL_STATE_H_GUARD_
#define GLOBAL_STATE_H_GUARD_

#include "ds/stringutils.h"
#include "vec.h"
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>

#define HASH64BIT uint_fast64_t
#define MAX_HASH_THREADS 16

enum StagesProcessing
{
	STAGE_PROC_NONE,
	STAGE_PROC_SCANNING,
	STAGE_PROC_VALIDATING,
	STAGE_PROC_HASHD64,
	STAGE_PROC_COMPARED64,
	STAGE_PROC_DECOUPLING,
	STAGE_PROC_HASHD256,
	STAGE_PROC_COMPARED256,
	STAGE_PROC_FINISHED
};

enum StagesMeta
{
	STAGE_NONE,
	STAGE_READY,
	STAGE_PROCESSING,
	STAGE_SORTING
};

typedef struct UIState
{
	/* Stages */
	int stage;
	int processingStage;

	/* Window controls */
	bool helpScreen;
	bool buttonApplyOptions;
	bool buttonNext;
	bool buttonDelLeft;
	bool buttonDelRight;
	bool buttonDelBoth;
	bool buttonLaunch;
	bool buttonReset;
	bool buttonStopSorting;
	bool buttonPause;

	/* Options */
	bool recursive;
	bool extraPassD256;
	float threshSlider;
	bool biggerIsBetter;
	int resolution;
	int threadNum;

	char * windowName;
	string * statusline;
	string * threshString;
	string * directoryPaths;
	string * dirPathCount;

	float progress;
	bool threadPaused;

	string * imgLeftPath;
	string * imgRightPath;
	string * imgLeftResolution;
	string * imgRightResolution;

	string * groupCount;
	string * groupSize;
	string * totalDupes;
	string * fullPaths;
	string * processingExplained;
} UIState;

typedef struct ProcessingOptions
{
	bool recursive;
	bool extraPassD256;
	float threshold;
	int threads;
} ProcessingOptions;

typedef struct Imagefile
{
	string * path;
	HASH64BIT * hash;
	bool hashed;
	bool disposed;
	struct ImageGroup * group;
} Imagefile;

typedef vec_t(Imagefile *) imagefile_vec_t;

typedef struct ImageGroup
{
	size_t hashlen;
	HASH64BIT * hash;
	imagefile_vec_t images;
} ImageGroup;

typedef vec_t(ImageGroup *) imagegroup_vec_t;
typedef vec_t(string *) string_vec_t;

typedef struct FilesState
{
	unsigned long hashedfiles;
	unsigned long failedfiles;
	unsigned long dupenum;
	int compareiter;
	string_vec_t dirs;
	imagegroup_vec_t groups;
	imagefile_vec_t images;
} FilesState;


void PUGS_Init ( void );

#endif
