using LitJson;
using Wizard;

namespace Cute;

public class GetiCloudUserDataTask : NetworkTask
{
	private class iCloudUserParams : PostParams
	{
		public string icloud_data = "";
	}

	public class VerifiediCloudBackupUserData
	{
		public int iCloudViewerId { get; set; }

		public string iCloudUserName { get; set; } = " - ";

		public string UserRankRotation { get; set; }

		public string UserRankUnlimited { get; set; }

		public bool HasUserData()
		{
			return iCloudViewerId != 0;
		}

		public void Reset()
		{
			iCloudViewerId = 0;
			iCloudUserName = " - ";
		}
	}

	private CuteNetworkDefine.ApiType apiType = CuteNetworkDefine.ApiType.CheckiCloudUser;

	public static readonly VerifiediCloudBackupUserData VerifiediCloudUserData = new VerifiediCloudBackupUserData();

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

	public void SetParameter(string iCloudData)
	{
		iCloudUserParams iCloudUserParams = new iCloudUserParams();
		iCloudUserParams.icloud_data = iCloudData;
		base.Params = iCloudUserParams;
	}

	protected override int Parse()
	{
		if (resultCode != 1)
		{
			return resultCode;
		}
		JsonData jsonData = base.ResponseData["data"];
		if (jsonData["icloud_data_verified"].ToBoolean())
		{
			VerifiediCloudUserData.iCloudViewerId = jsonData["icloud_viewer_id"].ToInt();
			VerifiediCloudUserData.iCloudUserName = jsonData["icloud_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 jsonData2 = base.ResponseData["data"]["rank"];
				if (jsonData2.Keys.Contains(text))
				{
					VerifiediCloudUserData.UserRankRotation = systemText.Get(jsonData2[text].ToString());
				}
				if (jsonData2.Keys.Contains(text2))
				{
					VerifiediCloudUserData.UserRankUnlimited = systemText.Get(jsonData2[text2].ToString());
				}
			}
		}
		return resultCode;
	}
}
