#ifndef DATA_H_
#define DATA_H_

// Author: Steve Talbot

#pragma once

using namespace std;

#include "AccountInfo.h"
#include "AccountFile.h"
#include "ErrorMessageIds.h"
#include "MessageIds.h"

#include <vector>
#include <string>
#include <iostream>

class Data {

public:
	Data();
	~Data();


	bool addAccountInfo( AccountInfo* account );
	bool removeAccountInfo( int id_ );
	bool hasAccountInfo( int id_ );
	bool hasFileAccountInfo( int id_ );
	AccountInfo* getAccountInfo( int id_ );
	vector<AccountInfo*>* getAccounts();

	bool isPinCorrect( int pn_, int id_ );

	// getters ..
	int getW();
	int getD();
	bool getNeedsToBeFlushedToFile( int id_ );
	AccountInfo* getCurrentAccountInfo();
	int getAttempts();
	int getMaxAttempts();
	int getMinBalance();
	int getOverdrawPenalty();
	vector<string*>* getErrorMessages();
	string* getErrorMessage( int position_ );
	string* getMessage( int position_ );

	// setters ..
	void setW( int w_ );
	void setD( int d_ );
	void setNeedsToBeFlushedToFile( int id_, bool needsToBeFlushedToFile_ );
	void setCurrentAccountInfo( AccountInfo* currentAccountInfo_ );
	void setAttempts( int attempts_ );
	void setMaxAttempts( int maxAttempts_ );
	void setMinBalance( int minBalance_ );
	void setOverdrawPenalty( int overdrawPenalty_ );
	void setErrorMessages( vector<string*>* errorMessages_ );
	void setErrorMessage( string* errorMessage_, int position_ );
	void setMessages( vector<string*>* messages_ );
	void setMessage( string* message_, int position_ );

	// "AccountFile" wrapper methods ..
	string getFileDrive();
	string getFileDirectory();
	string getFileName();

	void setFileDrive( string fileDrive_ );
	void setFileDirectory( string fileDirectory_ );
	void setFileName( string fileName_ );

	bool loadAccountInfoFromFile( int id_ );
	bool writeAccountInfoToFile( int accountIndex_ );

	AccountFile* getAccountFile();

	// utility methods ..
	int getTempId();
	void setTempId( int tempId_ );
	int getTempPin();
	void setTempPin( int tempPin_ );
	bool getIsCurrentAccountFromFile();
	void setIsCurrentAccountFromFile( bool isCurrentAccountFromFile_ );

	int findAccountIndex( int id_ );

	ErrorMessageIds* _errorMessageIds;

	MessageIds* _messageIds;

private:

	int _w;

	int _d;

	vector<bool>* _needsToBeFlushedToFile;		// tracks whether each "AccountInfo" in collection needs to be re-saved to file ..

	vector<AccountInfo*>* _accounts;

	AccountInfo* _currentAccountInfo;

	AccountFile* _accountFile;					// handles persistency operations (file read/write) ..

	int _attempts;

	int _maxAttempts;

	int _minBalance;

	int _overdrawPenalty;

	vector<string*>* _errorMessages;

	vector<string*>* _messages;

	string _errorMessage1;
	string _errorMessage2;
	string _errorMessage3;
	string _errorMessage4;
	string _errorMessage5;

	string _message1;
	string _message2;
	string _message3;
	string _message4;
	string _message5;

	// temp variables, used to store "id" and "pin" while validating login ..
	int _tempId;

	int _tempPin;

	// temp variable, used to identify whether "current account info" was loaded-in from file ..
	bool _isCurrentAccountFromFile;

};

#endif /*DATA_H_*/
