using System;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;

namespace Guru
{
	public class DeviceInfoUploadRequest : RequestBase
	{
		protected override string RequestURL => IPMConfig.IPM_URL + "device/api/v1/devices";
		
		protected override UnityWebRequest CreateRequest()
		{
			DeviceData deviceData = new DeviceData();
			this.Log($"send deviceData:{deviceData}");
			var request = new UnityWebRequest(RequestURL, "POST");
			request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(JsonUtility.ToJson(deviceData)));
			request.downloadHandler = new DownloadHandlerBuffer();
			request.SetRequestHeader(IPMConfig.Header_Param_ContentType, IPMConfig.Header_Value_ContentType);
			request.SetRequestHeader(IPMConfig.Header_Param_APPID, IPMConfig.IPM_X_APP_ID);
			request.SetRequestHeader(IPMConfig.Header_Param_ACCESS_TOKEN, IPMConfig.IPM_TOKEN);
			return request;
		}

		protected override void RequestSuccessCallBack(string response)
		{
			this.Log("@@@ Send OK!");
			IPMConfig.IS_UPLOAD_DEVICE_SUCCESS = true;
		}
	}
}