using LitJson;
using UnityEngine;

namespace Cute;

public class SignUpTask : NetworkTask
{
	private class LoginPostParams : PostParams
	{
		public string device_name = "";

		public string client_type = "";

		public string os_version = "";

		public string app_version = "";

		public string resource_version = "";

		public string carrier = "";
	}

	private CuteNetworkDefine.ApiType apiType;

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

	public void SetParameter()
	{
		LoginPostParams loginPostParams = new LoginPostParams();
		loginPostParams.device_name = Toolbox.DeviceManager.GetModelName();
		loginPostParams.client_type = Toolbox.DeviceManager.GetDeviceType().ToString();
		loginPostParams.os_version = Toolbox.DeviceManager.GetOsVersion();
		loginPostParams.app_version = Toolbox.DeviceManager.GetAppVersionName();
		loginPostParams.resource_version = "00000000";
		loginPostParams.carrier = Toolbox.DeviceManager.GetCarrier();
		base.Params = loginPostParams;
	}

	protected override int Parse()
	{
		JsonData jsonData = base.ResponseData["data_headers"];
		resultCode = jsonData["result_code"].ToInt();
		if (resultCode != 1)
		{
			return resultCode;
		}
		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;
			Certification.SessionId = "";
			AdjustManager.ViewerIDEvent();
			GameObject gameObject = GameObject.Find("OmotePlugin");
			if (gameObject != null)
			{
				OmotePlugin component = gameObject.GetComponent<OmotePlugin>();
				if (component != null)
				{
					component.SendConversion(text);
				}
			}
		}
		return resultCode;
	}
}
