using LitJson;

namespace Wizard.Scripts.Network.Data.TaskData.BuildDeckPurchase;

public class BuildDeckPurchaseInfoTask : BaseTask
{
	public class BuildDeckPurchaseInfoTaskParam : BaseParam
	{
		public int add_series_id;
	}

	public BuildDeckPurchaseInfoTask()
	{
		base.type = ApiType.Type.BuildDeckInfo;
	}

	public void SetParameter(int add_series_id)
	{
		BuildDeckPurchaseInfoTaskParam buildDeckPurchaseInfoTaskParam = new BuildDeckPurchaseInfoTaskParam();
		buildDeckPurchaseInfoTaskParam.add_series_id = add_series_id;
		base.Params = buildDeckPurchaseInfoTaskParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		Wizard.Data.BuildDeckPurchaseInfo.seriesList.Clear();
		JsonData jsonData = base.ResponseData["data"];
		for (int i = 0; i < jsonData.Count; i++)
		{
			int num2 = jsonData[i]["series_id"].ToInt();
			if (!Wizard.Data.Master.BuildDeckSeriesIdDic.ContainsKey(num2))
			{
				continue;
			}
			BuildDeckSeriesPurchaseInfo buildDeckSeriesPurchaseInfo = new BuildDeckSeriesPurchaseInfo();
			buildDeckSeriesPurchaseInfo._seriesId = num2;
			buildDeckSeriesPurchaseInfo._introduction = Wizard.Data.Master.BuildDeckSeriesIdDic[buildDeckSeriesPurchaseInfo._seriesId].Introduction;
			buildDeckSeriesPurchaseInfo._isNew = jsonData[i]["is_new"].ToBoolean();
			JsonData jsonData2 = jsonData[i]["products"];
			for (int j = 0; j < jsonData2.Count; j++)
			{
				BuildDeckProductInfo buildDeckProductInfo = new BuildDeckProductInfo();
				buildDeckProductInfo.product_id = jsonData2[j]["product_id"].ToInt();
				buildDeckProductInfo.leader_id = jsonData2[j]["leader_id"].ToInt();
				buildDeckProductInfo.deck_code = jsonData2[j]["deck_code"].ToString();
				buildDeckProductInfo.featured_card_id = jsonData2[j]["featured_card_id"].ToInt();
				buildDeckProductInfo.purchase_num_max = jsonData2[j]["purchase_num_max"].ToInt();
				buildDeckProductInfo.purchase_num_current = jsonData2[j]["purchase_num_current"].ToInt();
				buildDeckProductInfo.is_first_price = jsonData2[j]["is_first_price"].ToBoolean();
				ShopCommonSaleInfo shopCommonSaleInfo = new ShopCommonSaleInfo();
				string key = jsonData2[j]["product_name"].ToString();
				shopCommonSaleInfo.name = Wizard.Data.Master.GetBuildDeckProductText(key);
				shopCommonSaleInfo.path = jsonData2[j]["product_id"].ToString();
				if (jsonData2[j].Keys.Contains("price_crystal"))
				{
					shopCommonSaleInfo.costCrystal = jsonData2[j]["price_crystal"].ToInt();
				}
				if (jsonData2[j].Keys.Contains("price_rupy"))
				{
					shopCommonSaleInfo.costRupy = jsonData2[j]["price_rupy"].ToInt();
				}
				if (jsonData2[j].Keys.Contains("price_ticket"))
				{
					shopCommonSaleInfo.costTicket = jsonData2[j]["price_ticket"].ToInt();
				}
				if (jsonData2[j].Keys.Contains("ticket_id"))
				{
					shopCommonSaleInfo.costTicketItemId = jsonData2[j]["ticket_id"].ToInt();
					shopCommonSaleInfo.haveTicketNum = PlayerStaticData.GetHaveUserGoods(UserGoods.Type.Item, shopCommonSaleInfo.costTicketItemId.Value);
				}
				shopCommonSaleInfo.isFree = false;
				if (shopCommonSaleInfo.costCrystal.HasValue && shopCommonSaleInfo.costRupy.HasValue && shopCommonSaleInfo.costCrystal <= 0 && shopCommonSaleInfo.costRupy <= 0)
				{
					shopCommonSaleInfo.isFree = true;
				}
				shopCommonSaleInfo.expirtyTimeInfo = new ShopExpirtyInfo(jsonData2[j]["sales_period_info"]);
				buildDeckProductInfo.saleInfo = shopCommonSaleInfo;
				JsonData jsonData3 = jsonData2[j]["rewards"];
				for (int k = 0; k < jsonData3.Count; k++)
				{
					ShopCommonRewardInfo shopCommonRewardInfo = new ShopCommonRewardInfo();
					shopCommonRewardInfo.Type = jsonData3[k]["reward_type"].ToInt();
					shopCommonRewardInfo.UserGoodsId = jsonData3[k]["reward_detail_id"].ToLong();
					shopCommonRewardInfo.Num = jsonData3[k]["reward_number"].ToInt();
					buildDeckProductInfo.rewardInfoList.Add(shopCommonRewardInfo);
				}
				if (Wizard.Data.Master.BuildDeckCardListDic.ContainsKey(buildDeckProductInfo.product_id))
				{
					for (int l = 0; l < Wizard.Data.Master.BuildDeckCardListDic[buildDeckProductInfo.product_id].Count; l++)
					{
						buildDeckProductInfo.cardList.Add(Wizard.Data.Master.BuildDeckCardListDic[buildDeckProductInfo.product_id][l]);
					}
					buildDeckSeriesPurchaseInfo.productList.Add(buildDeckProductInfo);
				}
			}
			JsonData jsonData4 = jsonData[i]["series_rewards"];
			for (int m = 0; m < jsonData4.Count; m++)
			{
				PurchaseRewardInfo purchaseRewardInfo = new PurchaseRewardInfo();
				JsonData jsonData5 = jsonData4[m];
				string key2 = $"Shop_BuildDeckRewardNum_{(m + 1).ToString()}";
				purchaseRewardInfo.PurchaseNthText = Wizard.Data.SystemText.Get(key2);
				for (int n = 0; n < jsonData5["reward_list"].Count; n++)
				{
					ShopCommonRewardInfo shopCommonRewardInfo2 = new ShopCommonRewardInfo();
					shopCommonRewardInfo2.Type = jsonData5["reward_list"][n]["reward_type"].ToInt();
					shopCommonRewardInfo2.UserGoodsId = jsonData5["reward_list"][n]["reward_detail_id"].ToLong();
					shopCommonRewardInfo2.Num = jsonData5["reward_list"][n]["reward_number"].ToInt();
					purchaseRewardInfo.RewardInfoList.Add(shopCommonRewardInfo2);
				}
				purchaseRewardInfo.IsGet = jsonData4[m]["is_get"].ToBoolean();
				buildDeckSeriesPurchaseInfo.SeriesRewardList.Add(purchaseRewardInfo);
			}
			Wizard.Data.BuildDeckPurchaseInfo.seriesList.Add(buildDeckSeriesPurchaseInfo);
		}
		return num;
	}
}
