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

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

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

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

		public static int uniqueNameToId(string uniqueName)
		{
			ItemData.CreateData();
			NDebug.Assert(ItemData.commonIdManager.nameMap.ContainsKey(uniqueName), "傅き.持ち込みアイテムデータ\nユニーク名[" + uniqueName + "]をIDに変換できませんでした");
			return ItemData.commonIdManager.nameMap[uniqueName];
		}

		public static string IdToUniqueName(int id)
		{
			ItemData.CreateData();
			NDebug.Assert(ItemData.commonIdManager.idMap.ContainsKey(id), "傅き.持ち込みアイテムデータ\nID[" + id + "]をユニーク名に変換できませんでした");
			return ItemData.commonIdManager.idMap[id].Key;
		}

		public static ItemData.Data GetData(int id)
		{
			ItemData.CreateData();
			NDebug.Assert(ItemData.basicDatas.ContainsKey(id), "傅き.持ち込みアイテムデータ\nID[" + id + "]のデータは存在しません");
			return ItemData.basicDatas[id];
		}

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

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

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

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

		public static void CreateData()
		{
			if (ItemData.commonIdManager != null)
			{
				return;
			}
			ItemData.commonIdManager = new CsvCommonIdManager("kasizuki_item", "傅き.持ち込みアイテムデータ", CsvCommonIdManager.Type.IdAndUniqueName, null);
			ItemData.basicDatas = new Dictionary<int, ItemData.Data>();
			string[] array = new string[]
			{
				"list"
			};
			KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				string text = "kasizuki_item_" + 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 ItemData.commonIdManager.idMap)
			{
				int key = keyValuePair.Key;
				ItemData.Data value = new ItemData.Data(key, array2[0].Value);
				ItemData.basicDatas.Add(key, value);
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
		}

		private const string csvTopCommonName = "kasizuki_item";

		private const string typeNameForErrorLog = "傅き.持ち込みアイテムデータ";

		private static CsvCommonIdManager commonIdManager;

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

		public class Data
		{
			public Data(int uniqueID, CsvParser csv)
			{
				for (int i = 1; i < csv.max_cell_y; i++)
				{
					if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
					{
						int num = 1;
						this.ID = uniqueID;
						this.uniqueName = csv.GetCellAsString(num++, i);
						this.drawName = csv.GetCellAsString(num++, i);
						this.iconName = csv.GetCellAsString(num++, i);
						this.modelResourceName = csv.GetCellAsString(num++, i);
						this.categoryName = csv.GetCellAsString(num++, i);
					}
				}
			}

			public readonly int ID;

			public readonly string uniqueName;

			public readonly string drawName;

			public readonly string iconName;

			public readonly string modelResourceName;

			public readonly string categoryName;
		}
	}
}
