using Cute;
using DeckBuilder;
using LitJson;

namespace Wizard;

public class GetDeckDataFromCodeTask : BaseTask
{
	public class GetDeckDataFromCodeTaskParam : BaseParam
	{
		public string deck_code;
	}

	public override string Url => $"{CustomPreference.GetDeckBuilderServerURL()}{ApiType.ApiList[base.type]}";

	public GetDeckDataFromCodeTask()
	{
		base.type = ApiType.Type.GetDeckInfoFromDeckCode;
	}

	public void SetParameter(string deck_code)
	{
		GetDeckDataFromCodeTaskParam getDeckDataFromCodeTaskParam = new GetDeckDataFromCodeTaskParam();
		getDeckDataFromCodeTaskParam.deck_code = deck_code;
		base.Params = getDeckDataFromCodeTaskParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		Data.DeckDataFromDeckCode = new GetDeckDataFromCode();
		JsonData jsonData = base.ResponseData["data"]["deck"];
		int clanId = int.Parse(jsonData["clan"].ToString());
		int valueOrDefault = jsonData.GetValueOrDefault("sub_clan", 10);
		Data.DeckDataFromDeckCode.ClanId = clanId;
		Data.DeckDataFromDeckCode.SubClanId = valueOrDefault;
		Data.DeckDataFromDeckCode.IsSubClanSet = CardBasePrm.ClanTypeIsUseable((CardBasePrm.ClanType)Data.DeckDataFromDeckCode.SubClanId);
		string defaultValue = null;
		Data.DeckDataFromDeckCode.MyRotationId = jsonData.GetValueOrDefault("rotation_id", defaultValue);
		JsonData jsonData2 = jsonData["cardID"];
		int count = jsonData2.Count;
		Data.DeckDataFromDeckCode.CardIds = new int[count];
		for (int i = 0; i < count; i++)
		{
			Data.DeckDataFromDeckCode.CardIds[i] = jsonData2[i].ToInt();
		}
		return num;
	}
}
