/***************************************************************************
                Validation
                -----------------------------------------
	begin      : 2012/05/14
	copyright  : (C) 2011 SolutionBox Inc.
	author     : Service 1 Team
	email      : svc1@solbox.com
	version    : 3.1.0

    CopyRight(C) 2011 SolutionBox Inc. All Rights reserved.
    Redistribution and use in source and binary forms, with or with out
    modification, are not permitted in outside of SolutionBox Inc.
***************************************************************************/

#ifndef __VALIDATION_H__
#define __VALIDATION_H__

#include <vector>

# if __GNUC__ >= 3
#   include <ext/hash_map>
using namespace __gnu_cxx;
# else
#   include <hash_map>
# endif

struct hash_key2
{
	size_t operator() (const string &k) const
	{
		return __stl_hash_string(k.c_str());
	}
};
struct compare_key2
{
	bool operator () (const string s1, const string &s2) const
	{
		return s1 == s2;
	}
};

typedef hash_multimap<string, vector<string>, hash_key2, compare_key2> CCurretMap;

class DataBase;
class CValidation
{
public:
	CValidation(JOB_TYPE::JOB_TYPE type, vector<string> & input);
	~CValidation();

	int CheckData(bool first, CSyncData & outSync);

	void SetFHSMount(vector<string>& fhs) { m_fhsmount = fhs; }

private:
	bool	CompareData(DataBase *db, string& tblname, 
						vector<string> & vecFind, CSyncData & outSync);
	
	int		IsAllow();

	vector<string> MakeFind();

	void FindZero(string & inuri, CSyncData & outSync);
	void FindOne(vector<string> f, CSyncData & outSync);
	void FindOver(pair<CCurretMap::iterator, CCurretMap::iterator> &f, CSyncData & outSync);
	
	bool	GetCurrent(DataBase *db, string& tblname, bool useDisyplay = true);
	vector<string>	Current2Sync(string sflag, vector<string>& curr);

	string	GetFullFilenamehash();

	void	FreeDB(DataBase *db, bool success = true);
	DataBase* GetDB(string& tblname, bool & usedisplay);

	JOB_TYPE::JOB_TYPE	m_type;
	vector<string>		m_syncdata;	
	vector<string>		m_fhsmount;

	CCurretMap	m_current;

	bool		m_first;
};

#endif // __VALIDATION_H__
