#ifndef RECORD_H_
#define RECORD_H_

#include <Windows.h>
#include <iostream>
#include "MyExceptions.h"

namespace thermoCamera {

	enum class Flag {
		play = 0,
		pause = 1,
		stop = 2
	};

	enum class State {
		read = 0,
		write = 1
	};

	/**
	* @class Record
	* @brief Read write files, abstract class, interface
	* @author Matej Roman (student of BUT)
	*/
	class Record {

	public:

		/////////////////////////////////// Constructors /////////////////////////////

		/**
		* Standard constructor
		*/
		Record() :
			_eFlag(Flag::stop),
			_eState(State::read),
			_inputPath(NULL),
			_outPath(NULL),
			_nameImage(NULL),
			_format(NULL),
			_number(0)
		{}

		/////////////////////////////////// Destructor /////////////////////////////

		/**
		* Destructor
		*/
		virtual ~Record()
		{
			
			if (_inputPath) { delete[] _inputPath; _inputPath = NULL; }

			if (_outPath) { delete[] _outPath; _outPath = NULL; }

			if (_nameImage) { delete[] _nameImage; _nameImage = NULL; }

			if (_format) { delete[] _format; _format = NULL; }
		
		}

		/////////////////////////////////// Methods ///////////////////////////////////////////

		/**
		* Start recording
		* @param[in] number is not set if mode is read
		*/
		void startRecord(unsigned int number = 1);

		/**
		* Stop recording
		*/
		void stopRecord();

		/**
		* Pause recording
		*/
		void pauseRecord();


		/////////////////////////////////// Setters ///////////////////////////////////

		/**
		* Set image number
		* @param[in] input unsigned int number
		*/
		void setImageNumber(const unsigned int number);


		/////////////////////////////////// Getters //////////////////////////////////

		/**
		* Get flag
		* @param[out] flag: play = 0, pause = 1, stop = 2
		*/
		int getFlag() { return (int)_eFlag; }

		/**
		* Get current number of image
		* @param[out] unsigned int number
		*/
		unsigned int getCurrentNumber() { return _number; }

		/**
		* Get current path of folder
		* @param[out] char*, use in local function, don't save this address
		*/
		const TCHAR* getCurrentPath();

		/**
		* Get current path of image
		* @param[out] char*, use in local function, don't save this address
		*/
		const TCHAR* getCurrentImagePath();

	protected:

		TCHAR* _nameImage;
		
		/////////////////////////////////// Virtual Methods ///////////////////////////////////

		virtual void SetFormat() = 0;

		/////////////////////////////////// Methods ///////////////////////////////////////////

		void UpdateName();

		/////////////////////////////////// Setters ///////////////////////////////////

		/**
		* Set format
		* @param[in] this function is called from virtual function SetFormat() of Record class
		*/
		void setFormatOfImage(const TCHAR* format);

		/**
		* Set flag
		* @param[in] flag: play, pause, stop
		*/
		void setFlag(Flag flag) { _eFlag = flag; }

		/**
		* Set input path
		* @param[in] input path, the folder where the images belong
		*/
		void setInputPath(const TCHAR* inputPath);

		/**
		* Set output path
		* @param[in] output path, the folder where the images will be save
		*/
		void setOutputPath(const TCHAR* outPath);

		/**
		* Set state 0 for read or 1 for write
		* @param[in] 0 is read and 1 is write
		*/
		void setState(State state) { _eState = state; }

		/////////////////////////////////// Getters //////////////////////////////////

		/**
		* Get input path
		* @param[out] show to console
		*/
		void showInputPath() { if (_inputPath) std::cout << _inputPath << std::endl; }

		/**
		* Get input path
		* @param[out] show to console
		*/
		void showOutPath() { if (_outPath) std::cout << _outPath << std::endl; }

		/**
		* Get current name of image
		* @param[out] show to console
		*/
		void showNameImage() { if (_nameImage) std::cout << _nameImage << std::endl; }

		/**
		* Get state
		* @param[out] state 0 for read, 1 for write
		*/
		State getState() { return _eState; }

	private:

		Flag _eFlag;
		State _eState;

		TCHAR* _inputPath;
		TCHAR* _outPath;
		TCHAR* _format;

		unsigned int _number;

		void _UpdateCurrentNameImage();

		void _SetNameAndIncreaseNumber(TCHAR* path);

		void _RecognizeNumber(const TCHAR* path);
	};

}

#endif