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

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

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

		public static AppealData.Data GetData(int id)
		{
			AppealData.CreateData();
			NDebug.Assert(AppealData.basicDatas.ContainsKey(id), "傅き.アピール欄\nID[" + id + "]のデータは存在しません");
			return AppealData.basicDatas[id];
		}

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

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

		public static List<AppealData.Data> GetDatas(Func<AppealData.Data, bool> customCheckFunction)
		{
			AppealData.CreateData();
			List<AppealData.Data> list = new List<AppealData.Data>();
			foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in AppealData.commonIdManager.idMap)
			{
				AppealData.Data data = AppealData.basicDatas[keyValuePair.Key];
				if (customCheckFunction(data))
				{
					list.Add(data);
				}
			}
			return list;
		}

		public static List<AppealData.Data> GetDatas(Maid maid)
		{
			Func<AppealData.Data, bool> customCheckFunction = (AppealData.Data data) => data.personalUniqueName == maid.status.personal.uniqueName;
			return AppealData.GetDatas(customCheckFunction);
		}

		public static void CreateData()
		{
			if (AppealData.commonIdManager != null)
			{
				return;
			}
			AppealData.commonIdManager = new CsvCommonIdManager("kasizuki_appeal", "傅き.アピール欄", CsvCommonIdManager.Type.IdOnly, null);
			AppealData.basicDatas = new Dictionary<int, AppealData.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_appeal_" + 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 AppealData.commonIdManager.idMap)
			{
				int key = keyValuePair.Key;
				AppealData.Data value = new AppealData.Data(key, array2[0].Value);
				AppealData.basicDatas.Add(key, value);
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
		}

		private const string csvTopCommonName = "kasizuki_appeal";

		private const string typeNameForErrorLog = "傅き.アピール欄";

		private static CsvCommonIdManager commonIdManager;

		private static Dictionary<int, AppealData.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.personalUniqueName = csv.GetCellAsString(num++, i);
						this.texName = csv.GetCellAsString(num++, i);
					}
				}
			}

			public Texture2D GetTexture()
			{
				if (!string.IsNullOrEmpty(this.texName))
				{
					string f_strFileName = this.texName + ".tex";
					if (GameUty.FileSystem.IsExistentFile(f_strFileName))
					{
						return ImportCM.CreateTexture(f_strFileName);
					}
					Debug.LogWarningFormat("テクスチャ「{0}」がない", new object[]
					{
						this.texName
					});
				}
				else
				{
					Debug.LogWarning("テクスチャ名が空でした");
				}
				return null;
			}

			public readonly int ID;

			public readonly string personalUniqueName;

			public readonly string texName;
		}
	}
}
