using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;

namespace QC.QMine.QMineInterface;

[Serializable]
public class QMineConfig
{
	private static string qmineConfigPath = Path.Combine(Constants.QMineDataPath, "QMine30Config.config");

	private static int currentQMineVersion = 2;

	private int configVersion = 1;

	[DefaultValue(1)]
	public int QMineConfigVersion
	{
		get
		{
			return configVersion;
		}
		set
		{
			configVersion = value;
		}
	}

	public string ServerName
	{
		get
		{
			return QMineGlobalInformation.ServerName;
		}
		set
		{
			QMineGlobalInformation.ServerName = value;
		}
	}

	public string DatabaseName
	{
		get
		{
			return QMineGlobalInformation.DatabaseName;
		}
		set
		{
			QMineGlobalInformation.DatabaseName = value;
		}
	}

	public string ServerDescription
	{
		get
		{
			return QMineGlobalInformation.ServerDescription;
		}
		set
		{
			QMineGlobalInformation.ServerDescription = value;
		}
	}

	public string DatabaseDescription
	{
		get
		{
			return QMineGlobalInformation.DatabaseDescription;
		}
		set
		{
			QMineGlobalInformation.DatabaseDescription = value;
		}
	}

	public HashSet<string> LoopConditions
	{
		get
		{
			return QMineGlobalInformation.DefaultLoopConditions;
		}
		set
		{
			QMineGlobalInformation.DefaultLoopConditions = value;
		}
	}

	public int QMineTempFolderCleanupDays
	{
		get
		{
			return QMineGlobalInformation.QMineTempFolderCleanupDays;
		}
		set
		{
			QMineGlobalInformation.QMineTempFolderCleanupDays = value;
		}
	}

	public static void Save(QMineConfig qMineConfig)
	{
		CommonFunctions.Serialize(qmineConfigPath, qMineConfig);
	}

	public static QMineConfig Load()
	{
		if (File.Exists(qmineConfigPath))
		{
			QMineConfig qMineConfig = CommonFunctions.Deserialize<QMineConfig>(qmineConfigPath);
			if (qMineConfig != null)
			{
				if (qMineConfig.configVersion < currentQMineVersion)
				{
					qMineConfig.configVersion = currentQMineVersion;
				}
				return qMineConfig;
			}
			return new QMineConfig();
		}
		return new QMineConfig();
	}
}
