using LitJson;
using Wizard;

namespace Cute;

public class GetGameDataByTransitionCode : NetworkTask
{
	public class ChainedPlayData
	{
		public string ChainedViewerId { get; set; }

		public string Password { get; set; }

		public string UserName { get; set; }

		public string UserRankRotation { get; set; }

		public string UserRankUnlimited { get; set; }
	}

	private CuteNetworkDefine.ApiType apiType = CuteNetworkDefine.ApiType.GetGameDataByTransitionCode;

	public static ChainedPlayData ChainedPlayDatas { get; private set; }

	public static string NowUserName { get; private set; }

	public static string NowUserRankRotation { get; private set; }

	public static string NowUserRankUnlimited { get; private set; }

	public override string Url => $"{CustomPreference.GetApplicationServerURL()}{CuteNetworkDefine.ApiUrlList[apiType]}";

	public GetGameDataByTransitionCode()
	{
		ChainedPlayDatas = new ChainedPlayData();
	}

	public void SetParameter(string input_viewer_id, string password)
	{
		TransitionCodeParams transitionCodeParams = new TransitionCodeParams();
		transitionCodeParams.input_viewer_id = input_viewer_id;
		transitionCodeParams.password = password;
		base.Params = transitionCodeParams;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		ChainedPlayDatas.ChainedViewerId = "";
		ChainedPlayDatas.Password = "";
		ChainedPlayDatas.UserName = " - ";
		ChainedPlayDatas.UserRankRotation = " - ";
		ChainedPlayDatas.UserRankUnlimited = " - ";
		NowUserName = " - ";
		NowUserRankRotation = " - ";
		NowUserRankUnlimited = " - ";
		if (base.ResponseData["data"].Count > 0)
		{
			if (base.ResponseData["data"].Keys.Contains("chained_viewer_id") && base.ResponseData["data"]["chained_viewer_id"] != null && base.ResponseData["data"]["chained_viewer_id"].ToString() != "")
			{
				ChainedPlayDatas.ChainedViewerId = base.ResponseData["data"]["chained_viewer_id"].ToString();
			}
			if (base.ResponseData["data"].Keys.Contains("password") && base.ResponseData["data"]["password"] != null && base.ResponseData["data"]["password"].ToString() != "")
			{
				ChainedPlayDatas.Password = base.ResponseData["data"]["password"].ToString();
			}
			if (base.ResponseData["data"].Keys.Contains("name") && base.ResponseData["data"]["name"] != null && base.ResponseData["data"]["name"].ToString() != "")
			{
				ChainedPlayDatas.UserName = base.ResponseData["data"]["name"].ToString();
			}
			string text = 1.ToString();
			string text2 = 2.ToString();
			SystemText systemText = Data.SystemText;
			if (base.ResponseData["data"].Keys.Contains("rank") && base.ResponseData["data"]["rank"] != null)
			{
				JsonData jsonData = base.ResponseData["data"]["rank"];
				if (jsonData.Keys.Contains(text))
				{
					ChainedPlayDatas.UserRankRotation = systemText.Get(jsonData[text].ToString());
				}
				if (jsonData.Keys.Contains(text2))
				{
					ChainedPlayDatas.UserRankUnlimited = systemText.Get(jsonData[text2].ToString());
				}
			}
			NowUserName = base.ResponseData["data"]["now_name"].ToString();
			JsonData jsonData2 = base.ResponseData["data"]["now_rank"];
			NowUserRankRotation = systemText.Get(jsonData2[text].ToString());
			NowUserRankUnlimited = systemText.Get(jsonData2[text2].ToString());
		}
		return num;
	}
}
