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

namespace Wizard;

public class DeckIntroductionTask : BaseTask
{
	public class IntroductionData
	{
		public DeckData Deck { get; private set; }

		public string PlayerName { get; private set; }

		public string Detail { get; private set; }

		public int TopCardId { get; private set; }

		public IntroductionData(DeckData deck, string playerName, string detail, int topCardId)
		{
			Deck = deck;
			PlayerName = playerName;
			Detail = detail;
			TopCardId = topCardId;
		}
	}

	public class IntroductionDataTaskParam : BaseParam
	{
		public int series_id;
	}

	public List<IntroductionData> _result = new List<IntroductionData>();

	public Dictionary<Format, string> AlternativeFormatAndSeries;

	public List<int> ResultDeckSeriesIdList { get; private set; }

	public List<string> ResultDeckSeriesNameList { get; private set; }

	public List<bool> IsTimeSlipRotationList { get; private set; }

	public int DisplaySeriesId { get; private set; }

	public Format DisplayFormat { get; private set; }

	public void SetParameter(int series_id)
	{
		IntroductionDataTaskParam introductionDataTaskParam = new IntroductionDataTaskParam();
		introductionDataTaskParam.series_id = series_id;
		base.Params = introductionDataTaskParam;
	}

	public DeckIntroductionTask()
	{
		base.type = ApiType.Type.DeckIntroduction;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		JsonData jsonData = base.ResponseData["data"];
		DisplaySeriesId = jsonData["series_id"].ToInt();
		DisplayFormat = Data.ParseApiFormat(jsonData["display_format"].ToInt());
		JsonData jsonData2 = jsonData["display_deck_list"];
		for (int i = 0; i < jsonData2.Count; i++)
		{
			JsonData jsonData3 = jsonData2[i];
			DeckData deckData = new DeckData();
			deckData.Initialize(jsonData3);
			string playerName = jsonData3["player_name"].ToString();
			string detail = jsonData3["introduction"].ToString();
			int topCardId = jsonData3["thumbnail_card_id"].ToInt();
			IntroductionData item = new IntroductionData(deckData, playerName, detail, topCardId);
			_result.Add(item);
		}
		ResultDeckSeriesIdList = new List<int>();
		ResultDeckSeriesNameList = new List<string>();
		IsTimeSlipRotationList = new List<bool>();
		JsonData jsonData4 = jsonData["series_list"];
		for (int j = 0; j < jsonData4.Count; j++)
		{
			JsonData jsonData5 = jsonData4[j];
			int item2 = jsonData5["series_id"].ToInt();
			string item3 = jsonData5["series_name"].ToString();
			bool item4 = jsonData5["is_ts_rotation"].ToInt() == 1;
			ResultDeckSeriesIdList.Add(item2);
			ResultDeckSeriesNameList.Add(item3);
			IsTimeSlipRotationList.Add(item4);
		}
		if (jsonData.TryGetValue("alternative_list", out var value))
		{
			AlternativeFormatAndSeries = new Dictionary<Format, string>();
			foreach (JsonData item5 in (IEnumerable)value)
			{
				Format key = Data.ParseApiFormat(item5["alternative_format"].ToInt());
				AlternativeFormatAndSeries[key] = item5["alternative_series_name"].ToString();
			}
		}
		return num;
	}

	public bool IsExistClass(CardBasePrm.ClanType classType, Format format)
	{
		for (int i = 0; i < _result.Count; i++)
		{
			if (_result[i].Deck.GetDeckClassID() == (int)classType && _result[i].Deck.Format == format)
			{
				return true;
			}
		}
		return false;
	}

	public bool IsExistFormat(Format format)
	{
		for (int i = 0; i < _result.Count; i++)
		{
			if (_result[i].Deck.Format == format)
			{
				return true;
			}
		}
		return false;
	}
}
