#ifndef JSONOBJECT_H
#define JSONOBJECT_H

//#include <QObject>
#include <QString>
class QStringList;
class QTranslator;

#include <QString>
struct host {
	QString name;
	QString ae;
	QString ip;
	QString port;
	//QString isDefault;
};

struct IpAddr {
	QString ip;
	QString mask;
};
struct IpRoute
{
	QString des;
	QString gw;
	QString mask;
};


class JsonObject
{
public:

	static JsonObject* Instance()
	{
		static JsonObject obj;
		return &obj;
	}
	enum ServerType
	{
		WORKLIST, PACS, LOCAL, RECON
	};

	//
	QString storageAlarmSize();
	// 
	//for login
	void setDefaultUser(const QString& str);
	QString defaultUser();


	QStringList language();
	void setDefaultLanguage(const QString& str);
	QString defaultLanguage();

	QString institutionName();
	void setInstitutionName(const QString& str);

	QString institutionAddr();
	void setInstitutionAddr(const QString& str);

	int lockerCount();
	QString lockScreenTimeout();
	void setLockScreenTimeout(const QString& str);


	QStringList protocals();
	QString defaultProtocal();
	void setDefaultProtocal(const QString& str);


	QStringList worklistFilters();
	QString defaultFilter();
	void setDefaultFilter(const QString& str);

	host getServer(ServerType type);
	void setServer(ServerType type, const host& list);

	//for network manager

	QString passWord();
	void setPassword(const QString& pwd);

	QString interfaceName();
	void setInterfaceName(const QString& name);

	bool isDHCP();
	void autoDHCP(bool);

	IpAddr getDefaultIpAddr();
	void setDefaultIpAddr(const IpAddr& addr);

	QList<QStringList> getIpAddrList();
	void setIpAddrList(const QList<QStringList>& list);

	QString getDefaultGateway();
	void setDefaultGateway(const QString& gw);

	QList<QStringList> getIpRouteList();
	void setIpRouteList(const QList<QStringList>& list);


private:
	void  setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save = true);
	char* getJsonString(const char* catergory, const char* stringName);

	char* getArrayNode(const char* catergory, const char* stringName, int index, const char* id);
	void setArrayNode(const char* catergory, const char* stringName, int index, const char* id, const char* stringValue);
	int getArraySize(const char* catergory, const char* stringName);


	bool loadcfg();
	bool loadcfgDefault();
	bool savecfg();

	JsonObject();
	~JsonObject();

	void* json_root = nullptr;
	bool m_bLoaded = false;

	QString tmp_psw;
};

#endif // JSONOBJECT_H
