using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace SYNC_SAP_MES
{
    internal class CALL_Interfalce_WebAPI
    {
        public static SyncPlan_WebAPI_ResponseBody Get_Plans_ByWebAPI(string lineid, string startdate, string islocked)
        {
            var m_msgRequest = new SyncPlan_WebAPI_RequestBody
            {
                lineId = lineid,
                startDate = startdate,
                isLocked = islocked
            };

            return RequestPost_Plans_AMS_To_SAP(m_msgRequest);
        }
        public static SyncPlan_WebAPI_ResponseBody Get_BarCode_Plans_ByWebAPI(string lineid, string startdate)
        {
            var m_msgRequest = new SyncBarCodePlan_WebAPI_RequestBody
            {
                lineId = lineid,
                startDate = startdate + " 00:00:00",
                endDate = startdate + " 23:59:59"
            };

            return RequestPost_BarCode_Plans_AMS_To_SAP(m_msgRequest);
        }
        public static SyncPlan_WebAPI_ResponseBody RequestPost_BarCode_Plans_AMS_To_SAP(Object m_msg)
        {
            var demoData = JsonConvert.SerializeObject(m_msg);

            return JsonConvert.DeserializeObject<SyncPlan_WebAPI_ResponseBody>(HttpCli.Post(Program.WebAPI_Url_BarCodePlans, demoData));

            //var Gen_ProductPlan = File.ReadAllText("C:\\项目\\AMS计划下达.json");
            //return JsonConvert.DeserializeObject<SyncPlan_WebAPI_ResponseBody>(Gen_ProductPlan);
        }

        public static SyncPlan_WebAPI_ResponseBody RequestPost_Plans_AMS_To_SAP(Object m_msg)
        {
            var demoData = JsonConvert.SerializeObject(m_msg);

            return JsonConvert.DeserializeObject<SyncPlan_WebAPI_ResponseBody>(HttpCli.Post(Program.WebAPI_Url_Plans, demoData));

            //var Gen_ProductPlan = File.ReadAllText("C:\\项目\\AMS计划下达.json");
            //return JsonConvert.DeserializeObject<SyncPlan_WebAPI_ResponseBody>(Gen_ProductPlan);
        }

        public static ResponseBody_WebAPI_Boms Get_BOMs_ByWebAPI(string lineid, string productcode)
        {
            var m_msgRequest = new RequestBody_WebAPI_Boms
            {
                lineId = lineid,
                productCode = productcode
            };

            return RequestPost_Boms_AMS_To_SAP(m_msgRequest);
        }
        public static ResponseBody_WebAPI_Boms RequestPost_Boms_AMS_To_SAP(RequestBody_WebAPI_Boms m_msg)
        {
            var demoData = JsonConvert.SerializeObject(m_msg);
            return JsonConvert.DeserializeObject<ResponseBody_WebAPI_Boms>(HttpCli.Post(Program.WebAPI_Url_Boms, demoData));

            //var Gen_ProductPlan = File.ReadAllText("C:\\项目\\AMS计划下达.json");
            //return JsonConvert.DeserializeObject<ResponseBody_WebAPI_Boms>(Gen_ProductPlan);
        }

        public static SyncPlan_WebAPI_ResponseBody Put_MisFun_ByWebAPI(string type,string opName,string value = "")
        {
            var m_msgRequest = new DataBody_WebApi_MisFun
            {
                type = type,
                opName = opName,
                value = value
            };
            var jsonData = JsonConvert.SerializeObject(m_msgRequest);

            return JsonConvert.DeserializeObject<SyncPlan_WebAPI_ResponseBody>(HttpCli.Post(Program.WebAPI_Url_MisFun, jsonData));
        }
    }

}
