using LitJson;

namespace Cute;

public class UpdateiCloudUserDataTask : NetworkTask
{
	private class iCloudUserParams : PostParams
	{
		public string carrier = "";

		public string icloud_data = "";
	}

	private CuteNetworkDefine.ApiType apiType = CuteNetworkDefine.ApiType.MigrateiCloudUser;

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

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

	protected override int Parse()
	{
		if (resultCode != 1)
		{
			return base.Parse();
		}
		JsonData jsonData = base.ResponseData["data_headers"];
		int viewerId = jsonData["viewer_id"].ToInt();
		int shortUdid = jsonData["short_udid"].ToInt();
		string text = jsonData["udid"].ToString();
		if (Certification.Udid != text)
		{
			Debug.LogError("udid一致しません。不正のアクセスです。");
		}
		else
		{
			Certification.ViewerId = viewerId;
			Certification.ShortUdid = shortUdid;
		}
		return resultCode;
	}
}
