using System;
using System.Collections.Generic;
using LitJson;

namespace Wizard;

public class BattlePassPurchaseInfoTask : BaseTask
{
	public BattlePassPurchaseInfo PurchaseInfo { get; private set; }

	public BattlePassPurchaseInfoTask()
	{
		base.type = ApiType.Type.BattlePassItemList;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		JsonData jsonData = base.ResponseData["data"];
		string text = jsonData["premium_pass_description"].ToString();
		text = text.Replace("\\n", "\n");
		if (jsonData.Keys.Contains("sales_period_info") && jsonData["sales_period_info"].Keys.Contains("sales_period_time"))
		{
			string arg = ConvertTime.ToLocal(DateTime.Parse(jsonData["sales_period_info"]["sales_period_time"].ToString()));
			text = string.Format(text, arg);
		}
		List<BattlePassProduct> list = new List<BattlePassProduct>();
		JsonData jsonData2 = jsonData["products"];
		for (int i = 0; i < jsonData2.Count; i++)
		{
			int id = jsonData2[i]["id"].ToInt();
			int seasonId = jsonData2[i]["season_id"].ToInt();
			string name = jsonData2[i]["name"].ToString();
			int priceInCrystal = jsonData2[i]["price_crystal"].ToInt();
			string text2 = jsonData2[i]["description"].ToString();
			text2 = text2.Replace("\\n", "\n");
			ShopExpirtyInfo expirtyInfo = new ShopExpirtyInfo(jsonData2[i]["sales_period_info"]);
			list.Add(new BattlePassProduct(id, seasonId, name, priceInCrystal, text2, expirtyInfo));
		}
		PurchaseInfo = new BattlePassPurchaseInfo(text, list);
		return num;
	}
}
