using MaxCommunication.DataBase.Document;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pms.WebHandle
{

    class SKMESWebServiceHelper
    {
        public static string addressWebsite = UriSetting.g_MESUri;//"http://127.0.0.1:8634/casunsystem/"
        static RestRequestHelper requestHelperForClient = new RestRequestHelper(addressWebsite);
        /// <summary>
        /// 对应接口编号004
        /// </summary>
        /// <returns></returns>
        public static AGVStateResponse UpdateAGVState(AGVState alarmAppearReport)
        {
            //string data = JsonHelper.ConvertToJson(typeof(AGVState), alarmAppearReport);
            //TextDocument.WriteFile(@"PMS/Log","异常报警上报", "请求:" + data);
            //string uri = "UpdateAGVState";//api/OutService.IntelligentStorage.IntelligentForklift/
            //string strBeforeDecrypt = requestHelperForClient.PostWithWholeURI(data, UriSetting.g_MESUri + "/" + uri);
            //TextDocument.WriteFile(@"PMS/Log","异常报警上报", "返回:" + strBeforeDecrypt);
            //AGVStateResponse returnValue = (AGVStateResponse)JsonHelper.ConvertToObject(typeof(AGVStateResponse), strBeforeDecrypt);
            //return returnValue;
            string data = JsonHelper.ConvertToJson(typeof(AGVState), alarmAppearReport);
            TextDocument.WriteFile(@"PMS/Log", "AGV状态上报", "请求:" + data);
            string uri = "UpdateAGVState/info";//api/OutService.IntelligentStorage.IntelligentForklift/
            string strBeforeDecrypt = requestHelperForClient.PostWithWholeURI(data, UriSetting.g_MESUri + "/" + uri);
            TextDocument.WriteFile(@"PMS/Log", "AGV状态上报", "返回:" + strBeforeDecrypt);
            AGVStateResponse returnValue = new AGVStateResponse() { code = strBeforeDecrypt }; //(AGVStateResponse)JsonHelper.ConvertToObject(typeof(AGVStateResponse), strBeforeDecrypt);
            return returnValue;
        }

        /// <summary>
        /// 对应接口编号005
        /// </summary>
        /// <returns></returns>
        public static TaskStateResponse UpdateTaskState(TaskState alarmDisappearReport)
        {
            //string data = JsonHelper.ConvertToJson(typeof(TaskState), alarmDisappearReport);
            //TextDocument.WriteFile(@"PMS/Log","报警消除上报", "请求:" + data);
            //string uri = "UpdateTaskState";//api/OutService.IntelligentStorage.IntelligentForklift/
            //string strBeforeDecrypt = requestHelperForClient.PostWithWholeURI(data, UriSetting.g_MESUri + "/" + uri);
            //TextDocument.WriteFile(@"PMS/Log","报警消除上报", "返回:" + strBeforeDecrypt);
            //TaskStateResponse returnValue = (TaskStateResponse)JsonHelper.ConvertToObject(typeof(TaskStateResponse), strBeforeDecrypt);
            //return returnValue;
            string data = JsonHelper.ConvertToJson(typeof(TaskState), alarmDisappearReport);
            TextDocument.WriteFile(@"PMS/Log", "任务状态上报", "请求:" + data);
            string uri = "UpdateTaskState/info";//api/OutService.IntelligentStorage.IntelligentForklift/
            string strBeforeDecrypt = requestHelperForClient.PostWithWholeURI(data, UriSetting.g_MESUri + "/" + uri);
            TextDocument.WriteFile(@"PMS/Log", "任务状态上报", "返回:" + strBeforeDecrypt);
            TaskStateResponse returnValue = new TaskStateResponse();
            try
            {
                returnValue = (TaskStateResponse)JsonHelper.ConvertToObject(typeof(TaskStateResponse), strBeforeDecrypt);
            }
            catch
            {
                returnValue.code = strBeforeDecrypt;
            }
            return returnValue;
        }

    }
}

