using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Collections.Concurrent;
using Newtonsoft.Json.Linq;
using System.Threading;
using System.Net;
using System.Net.Http.Headers;
using System.IO;
using MisDataSaveDate;

namespace MisDataSaveDate
{
    /// <summary>
    /// AGV接口控制器
    /// </summary>
    public class AGVController : ApiController
    {
        readonly string headUrl = "agv/";

        /// <summary>
        /// AGV请求进入离开、下降举升接口（接收方）
        /// 接收AGV的进入、离开、下降、举升请求并存储到数据库
        /// </summary>
        /// <param name="jobj">AGV请求数据</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        [Route("agv/agvReqInOut")]
        public HttpResponseMessage agvReqInOut([FromBody] JObject jobj)
        {
            return new HttpResponseMessage
            {
                Content = new StringContent(AGV_BusinessLogic.ProcessAGVEnterRequest(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 临工AGV到达/离开状态回调接口。
        /// </summary>
        /// <param name="jobj">临工AGV状态回调数据</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        [Route("agv/lgagv/statusUpdate")]
        public HttpResponseMessage LGAGV_StatusUpdate([FromBody] JObject jobj)
        {
            return new HttpResponseMessage
            {
                Content = new StringContent(LGAGV_BusinessLogic.ProcessStatusUpdate(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 临工AGV任务结果回调接口。
        /// </summary>
        /// <param name="jobj">临工AGV任务结果数据</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        [Route("agv/lgagv/taskResult")]
        public HttpResponseMessage LGAGV_TaskResult([FromBody] JObject jobj)
        {
            return new HttpResponseMessage
            {
                Content = new StringContent(LGAGV_BusinessLogic.ProcessTaskResult(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

    }
}
