using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using MisDataSaveDate.MOM;
using Newtonsoft.Json;
using System.Configuration;
using ExternalDataSync;
namespace WebApi
{
    public class CALL_Interface_WebAPI
    {

        public static JObject CALL_WebApi_CallMaterial(string InterfaceUrl, MaterialSend entity_send)
        {
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_CallMaterial"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_DeviceInfoQuery(string InterfaceUrl, DeviceInfo entity_send)
        {
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_DeviceInfoQuery"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_MaterialConfirm(string InterfaceUrl, MaterialConfirm entity_send)
        {
            //var InterfaceUrl = CallWebApiUrl_MaterialInfoConfirm;
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_MaterialInfoConfirm"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_JobStart(string InterfaceUrl, JobStart entity_send)
        {
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_ProcessJobStart"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_DeviceAlarm(string InterfaceUrl, DeviceAlarm entity_send)
        {
            //var InterfaceUrl = CallWebApiUrl_AlarmInfoUpload;
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_AlarmInfoUpload"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_JobFinished(string InterfaceUrl, JobFinished entity_send)
        {
            //var InterfaceUrl = CallWebApiUrl_ProcessJobFinish;
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_ProcessJobFinish"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_FinishedReport(TaskFinish entity_send)
        {
            //var InterfaceUrl = CallWebApiUrl_TaskFinishedReport;
            string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_TaskFinishedReport"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_MaterialTransfer(string InterfaceUrl, MaterialTransfer entity_send)
        {
            //string InterfaceUrl = ConfigurationManager.AppSettings["CallWebApiUrl_MaterialTransfer"];
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject CALL_WebApi_SpotCheckRecord(string InterfaceUrl, SpotCheckResult entity_send)
        {
            string bodydata = JsonConvert.SerializeObject(entity_send);
            return Post_WebAPI(InterfaceUrl, bodydata);
        }
        public static JObject Post_WebAPI(string WebAPI_Url, string m_msg)
        {
            try
            {
                if (StateVariable.online_Mes)
                {
                    return JsonConvert.DeserializeObject<JObject>(WebApi.Post.Post_XK(WebAPI_Url, m_msg));
                }
                else
                {
                    return JObject.Parse("{\"code\":404,\"离线工作模式，请求暂存。\":\"\",\"data\":{}}");
                }
            }
            catch (Exception ex)
            {
                return new JObject { { "code", 500 }, { "Message", ex.Message }, { "data", new JObject() } };
            }

        }
    }

}
