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

public class ProductParse : MonoBehaviour
{
	public string ID
	{
		get
		{
			return this.m_strID;
		}
	}

	public string GetName()
	{
		return this.GetData(ProductParse.KEY_NAME);
	}

	public int GetPrice()
	{
		int result;
		try
		{
			int num = -1;
			string data = this.GetData(ProductParse.KEY_PRICE);
			if (!int.TryParse(data, out num))
			{
				throw new Exception("値段のデータに不正な値が入っている\n値：" + data);
			}
			result = num;
		}
		catch (Exception ex)
		{
			NDebug.Assert(ex.Message, false);
			Debug.LogError(ex.Message);
			result = 0;
		}
		return result;
	}

	public string GetImageName()
	{
		return this.GetData(ProductParse.KEY_IMAGE);
	}

	public string GetDescription()
	{
		return this.GetData(ProductParse.KEY_DESC);
	}

	private static void InitProductList()
	{
		if (ProductParse.m_ProductList != null)
		{
			return;
		}
		ProductParse.m_ProductList = new Dictionary<string, Dictionary<string, string>>();
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		dictionary.Add(string.Empty, string.Empty);
	}

	private Dictionary<string, string> GetDataDic()
	{
		ProductParse.InitProductList();
		Dictionary<string, string> result;
		try
		{
			if (!ProductParse.m_ProductList.ContainsKey(this.m_strID))
			{
				throw new Exception("商品ID[" + this.m_strID + "]の情報が存在しない");
			}
			result = ProductParse.m_ProductList[this.m_strID];
		}
		catch (Exception ex)
		{
			NDebug.Assert(ex.Message, false);
			Debug.LogError(ex.Message);
			result = null;
		}
		return result;
	}

	private string GetData(string key)
	{
		string result;
		try
		{
			Dictionary<string, string> dataDic = this.GetDataDic();
			if (!dataDic.ContainsKey(key))
			{
				throw new Exception("商品データのキー[" + key + "]は存在しない");
			}
			result = dataDic[key];
		}
		catch (Exception ex)
		{
			NDebug.Assert(ex.Message, false);
			Debug.LogError(ex.Message);
			result = null;
		}
		return result;
	}

	private static string KEY_NAME = "name";

	private static string KEY_PRICE = "price";

	private static string KEY_IMAGE = "image";

	private static string KEY_DESC = "desc";

	private static Dictionary<string, Dictionary<string, string>> m_ProductList;

	private string m_strID;
}
