using System.Collections.Generic;
using LitJson;

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

public class SpotCardExchangeInfoTask : BaseTask
{
	public class PrereleaseExchangeInfo
	{
		private int _exchangeablePrereleaseCardLimit;

		private int _exchangedPrereleaseCardCount;

		public bool IsPrerelease { get; private set; }

		public int RemainingExchangeableCount
		{
			get
			{
				if (IsPrerelease)
				{
					return _exchangeablePrereleaseCardLimit - _exchangedPrereleaseCardCount;
				}
				return 0;
			}
		}

		public PrereleaseExchangeInfo(JsonData jsonData)
		{
			IsPrerelease = jsonData["is_pre_release"].ToBoolean();
			_exchangeablePrereleaseCardLimit = jsonData["pre_release_spot_card_exchange_limit"].ToInt();
			_exchangedPrereleaseCardCount = jsonData["pre_release_spot_card_exchange_count"].ToInt();
		}
	}

	public Dictionary<CardBasePrm.ClanType, List<SpotCardExchangeInfo>> ExchangeableSpotCardListInClassDict { get; private set; }

	public int NextCycleOutPackId { get; private set; }

	public PrereleaseExchangeInfo PrereleaseInfo { get; private set; }

	public SpotCardExchangeInfoTask()
	{
		base.type = ApiType.Type.SpotCardInfo;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		JsonData jsonData = base.ResponseData["data"];
		PlayerStaticData.UserSpotCardPointCount = jsonData["spot_point"].ToInt();
		ExchangeableSpotCardListInClassDict = new Dictionary<CardBasePrm.ClanType, List<SpotCardExchangeInfo>>();
		for (CardBasePrm.ClanType clanType = CardBasePrm.ClanType.ALL; clanType < CardBasePrm.ClanType.MAX; clanType++)
		{
			ExchangeableSpotCardListInClassDict[clanType] = new List<SpotCardExchangeInfo>();
			JsonData jsonData2 = jsonData["exchangeable_card_list"][(int)clanType];
			List<string> list = new List<string>(jsonData2.Keys);
			for (int i = 0; i < list.Count; i++)
			{
				JsonData jsonData3 = jsonData2[list[i]];
				for (int j = 0; j < jsonData3.Count; j++)
				{
					SpotCardExchangeInfo item = new SpotCardExchangeInfo(jsonData3[j], int.Parse(list[i]));
					ExchangeableSpotCardListInClassDict[clanType].Add(item);
				}
			}
		}
		int.TryParse(jsonData["soon_cycle_out_card_set_id"].ToString(), out var result);
		NextCycleOutPackId = result;
		PrereleaseInfo = new PrereleaseExchangeInfo(jsonData["pre_relase_info"]);
		return num;
	}
}
