using LitJson;

namespace Cute;

public class PaymentItemListTask : NetworkTask
{
	private CuteNetworkDefine.ApiType apiType = CuteNetworkDefine.ApiType.PaymentItemList;

	public override string Url => $"{CustomPreference.GetApplicationServerURL()}{CuteNetworkDefine.ApiUrlList[apiType]}";

	protected override int Parse()
	{
		PaymentImpl instance = PaymentImpl.GetInstance();
		resultCode = (int)base.ResponseData["data_headers"]["result_code"];
		if (resultCode != 1)
		{
			return resultCode;
		}
		JsonData jsonData = base.ResponseData["data"];
		instance.ProductIdList.Clear();
		instance.IdList.Clear();
		instance.ProductNameList.Clear();
		instance.ProductPriceList.Clear();
		instance.ProductTextList.Clear();
		instance.ProductPurchaseLimitList.Clear();
		instance.ProductPurchaseNumberList.Clear();
		instance.FormatProductPriceList.Clear();
		instance.ProductCsvIdList.Clear();
		instance.ProductImageNameList.Clear();
		instance.ProductIsSpecialShop.Clear();
		instance.ProductCurrentPurchaseCount.Clear();
		instance.ProductPurchaseLimitCount.Clear();
		instance.ProductEndTime.Clear();
		for (int i = 0; i < jsonData.Count; i++)
		{
			JsonData jsonData2 = jsonData[i];
			string text = jsonData2["store_product_id"].ToString();
			string value = jsonData2["name"].ToString().Replace("\\n", "\n");
			string value2 = jsonData2["text"].ToString();
			string text2 = jsonData2["purchase_limit"].ToString();
			string text3 = jsonData2["id"].ToString();
			string value3 = jsonData2["image_name"].ToString();
			string value4 = jsonData2["end_time"].ToString();
			bool value5 = ((jsonData2["special_shop_flag"].ToInt() != 0) ? true : false);
			instance.ProductIdList.Add(text);
			instance.IdList.Add(text3);
			instance.ProductNameList.Add(text, value);
			instance.ProductTextList.Add(text, value2);
			instance.ProductPurchaseLimitList.Add(text3, text2);
			instance.ProductPurchaseLimitCount.Add(text, int.Parse(text2));
			instance.ProductImageNameList.Add(text, value3);
			if (jsonData2.Keys.Contains("number_of_product_purchased") && jsonData2["number_of_product_purchased"] != null)
			{
				string text4 = jsonData2["number_of_product_purchased"].ToString();
				instance.ProductPurchaseNumberList.Add(text3, text4);
				instance.ProductCurrentPurchaseCount.Add(text, int.Parse(text4));
			}
			instance.ProductCsvIdList.Add(text, text3);
			instance.ProductIsSpecialShop.Add(text, value5);
			instance.ProductEndTime.Add(text, value4);
		}
		return resultCode;
	}
}
