using System;
using System.Collections.Generic;
using System.Windows.Media;
using MECF.Framework.Common.SCCore;

namespace Aitex.Core.RT.SCCore
{
	public static class SC
	{
		public static ISCManager Manager { private get; set; }

		private static Dictionary<string, ISCManager> ModularManager { get; set; } = new Dictionary<string, ISCManager>();


		public static void SetItemValue(string name, object value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}

		public static void SetItemValue(string name, bool value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}

		public static void SetItemValue(string name, int value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}

		public static void SetItemValue(string name, double value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}

		public static void SetItemValue(string name, string value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}

		public static void SetItemValue(string name, Color value, bool temporarily = false)
		{
			Manager?.SetItemValue(name, value, temporarily);
		}
		
		public static SCConfigItem GetConfigItem(string name)
		{
			return Manager?.GetConfigItem(name);
		}

		public static bool ContainsItem(string name)
		{
			return Manager != null && Manager.ContainsItem(name);
		}

		public static SCConfigItem GetConfigItem(string path, string name)
		{
			return GetConfigItem(path + "." + name);
		}

		public static T GetValue<T>(string name, T defValue = default) where T : struct
		{
			return Manager?.GetValue<T>(name) ?? defValue;
		}

		public static string GetStringValue(string name)
		{
			return Manager?.GetStringValue(name);
		}

		public static T SafeGetValue<T>(string name, T defaultValue) where T : struct
		{
			return Manager?.SafeGetValue(name, defaultValue) ?? default(T);
		}

		public static string SafeGetStringValue(string name, string defaultValue)
		{
			return Manager?.SafeGetStringValue(name, defaultValue);
		}

		public static List<SCConfigItem> GetItemList()
		{
			return Manager?.GetItemList();
		}

		public static string GetConfigFileContent()
		{
			return Manager != null ? Manager.GetFileContent() : "";
		}

		public static string GetConfigFileContent(string module)
		{
			if (Manager != null && ModularManager != null && ModularManager.ContainsKey(module) && ModularManager[module] != null)
			{
				return ModularManager[module].GetFileContent();
			}
			return GetConfigFileContent();
		}

		public static void RegisterValueChangedCallback(string name, Action<object> newValue)
		{
			Manager?.RegisterValueChangedCallback(name, newValue);
		}
	}
}
