using System.Net.Http;
using System.Text;
using System.Web.Http;
using Newtonsoft.Json.Linq;

namespace MisDataSaveDate
{
    public class WebSendController : ApiController
    {
        readonly string headUrl = "WebSend/";

        [HttpPost]
        
        [Route("ApiFailRetry")]
        public HttpResponseMessage ReceiveMomPlanData([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.ApiFailRetry(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
        [HttpPost]
        [Route("FirstProductUpLoad")]
        public HttpResponseMessage FirstProductUpLoad([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.FirstProductUpLoad(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        [HttpPost]
        [Route("UploadImageToShare")]
        public HttpResponseMessage UploadImageToShare([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.UploadImageToShare(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 获取产品生产状态接口
        /// </summary>
        /// <param name="jobj">请求参数：MsgId, Site(默认2700), Barcode</param>
        /// <returns>返回产品状态信息及原始XML响应</returns>
        [HttpPost]
        [Route("GetSfcStatusAndOperation")]
        public HttpResponseMessage GetSfcStatusAndOperation([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.GetSfcStatusAndOperation(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 前端主动触发设备报警
        /// </summary>
        /// <param name="jobj">请求参数：MsgId, OpName, AlarmText, AlarmCode</param>
        /// <returns>触发结果</returns>
        [HttpPost]
        [Route("TriggerDeviceAlarm")]
        public HttpResponseMessage TriggerDeviceAlarm([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.TriggerDeviceAlarm(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 获取客户标签码
        /// </summary>
        /// <param name="jobj">请求参数：MsgId, EngineID, EngineTypeID</param>
        /// <returns>客户标签码值</returns>
        [HttpPost]
        [Route("GetClientTagValue")]
        public HttpResponseMessage GetClientTagValue([FromBody] JObject jobj)
        {
            var url = Request.RequestUri.ToString();
            return new HttpResponseMessage
            {
                Content = new StringContent(WebSendServer.GetClientTagValue(url, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
    }
}
