using System;
using System.Collections.Generic;
using wf;

namespace MaidStatus
{
	public static class Feature
	{
		public static int Count
		{
			get
			{
				Feature.CreateData();
				return Feature.commonIdManager.idMap.Count;
			}
		}

		public static bool Contains(string name)
		{
			return Feature.commonIdManager.nameMap.ContainsKey(name);
		}

		public static bool Contains(int id)
		{
			return Feature.commonIdManager.idMap.ContainsKey(id);
		}

		public static int uniqueNameToId(string name)
		{
			Feature.CreateData();
			NDebug.Assert(Feature.commonIdManager.nameMap.ContainsKey(name), "特徴\nユニーク名[" + name + "]をIDに変換できませんでした");
			return Feature.commonIdManager.nameMap[name];
		}

		public static string IdToUniqueName(int id)
		{
			Feature.CreateData();
			NDebug.Assert(Feature.commonIdManager.idMap.ContainsKey(id), "特徴\nID[" + id + "]をユニーク名に変換できませんでした");
			return Feature.commonIdManager.idMap[id].Key;
		}

		public static Feature.Data GetData(int id)
		{
			Feature.CreateData();
			NDebug.Assert(Feature.basicDatas.ContainsKey(id), "特徴\nID[" + id + "]のデータは存在しません");
			return Feature.basicDatas[id];
		}

		public static Feature.Data GetData(string uniqueName)
		{
			return Feature.GetData(Feature.uniqueNameToId(uniqueName));
		}

		public static bool IsEnabled(string uniqueName)
		{
			Feature.CreateData();
			return Feature.commonIdManager.enabledIdList.Contains(Feature.uniqueNameToId(uniqueName));
		}

		public static bool IsEnabled(int id)
		{
			Feature.CreateData();
			return Feature.commonIdManager.enabledIdList.Contains(id);
		}

		public static List<Feature.Data> GetAllDatas(bool onlyEnabled)
		{
			Feature.CreateData();
			List<Feature.Data> list = new List<Feature.Data>();
			foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in Feature.commonIdManager.idMap)
			{
				if (!onlyEnabled || Feature.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
				{
					list.Add(Feature.basicDatas[keyValuePair.Key]);
				}
			}
			return list;
		}

		public static void CreateData()
		{
			if (Feature.commonIdManager != null)
			{
				return;
			}
			Feature.commonIdManager = new CsvCommonIdManager("maid_status_feature", "特徴", CsvCommonIdManager.Type.IdAndUniqueName, null);
			Feature.basicDatas = new Dictionary<int, Feature.Data>();
			string[] array = new string[]
			{
				"list",
				"correction"
			};
			KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				string text = "maid_status_feature_" + array[i] + ".nei";
				AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
				CsvParser csvParser = new CsvParser();
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
			}
			foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in Feature.commonIdManager.idMap)
			{
				Feature.basicDatas.Add(keyValuePair.Key, new Feature.Data(keyValuePair.Key, array2[0].Value, array2[1].Value));
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
		}

		private const string csvTopCommonName = "maid_status_feature";

		private const string typeNameForErrorLog = "特徴";

		public const string termRootText = "MaidStatus/性癖タイプ/";

		private static CsvCommonIdManager commonIdManager;

		private static Dictionary<int, Feature.Data> basicDatas;

		public class Data
		{
			public Data(int id, CsvParser basicCsv, CsvParser bonusCorrectionCsv)
			{
				for (int i = 1; i < basicCsv.max_cell_y; i++)
				{
					if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == id)
					{
						int num = 1;
						this.id = id;
						this.uniqueName = basicCsv.GetCellAsString(num++, i);
						this.drawName = basicCsv.GetCellAsString(num++, i);
						break;
					}
				}
				for (int j = 1; j < bonusCorrectionCsv.max_cell_y; j++)
				{
					if (bonusCorrectionCsv.IsCellToExistData(0, j) && bonusCorrectionCsv.GetCellAsInteger(0, j) == id)
					{
						int num2 = 1;
						this.bonusCorrection = new ParametersPack();
						this.bonusCorrection.Parse(bonusCorrectionCsv.GetCellAsString(num2++, j), ',');
						break;
					}
				}
			}

			public string termName
			{
				get
				{
					return "MaidStatus/性癖タイプ/" + this.uniqueName;
				}
			}

			public readonly int id;

			public readonly string uniqueName;

			public readonly string drawName;

			public readonly ParametersPack bonusCorrection;
		}
	}
}
