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

/////http://127.0.0.1:9981/api/IOrder/InsertOrder

/// <summary>
/// 
/// </summary>
namespace WebApi
{
    /// <summary>
    /// 
    /// </summary>
    [RoutePrefix("api/imes")]
    public class imesController : ApiController
    {
        readonly string headUrl = "api/imes/";

        [HttpPost]
        public HttpResponseMessage TestPost([FromBody] JObject jobj)
        {
            if (jobj == null) jobj = new JObject();
            return new HttpResponseMessage
            {
                Content = new StringContent(ServerController.TestPost(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj.ToString()), Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// WEB发送请求给WEB API 注意 这是异步操作
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<HttpResponseMessage> MES_To_AGV_From_WEB([FromBody] JObject jobj)
        {
            if (jobj == null) jobj = new JObject();
            var result = await ServerController.MES_To_AGV_From_WEB(headUrl + "MES_To_AGV_From_WEB", jobj.ToString());
            return new HttpResponseMessage
            {
                Content = new StringContent(result, Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// WEB发送请求给WEB API 注意 这是异步操作
        /// 测试版
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<HttpResponseMessage> MES_To_AGV_From_WEB_Test([FromBody] JObject jobj)
        {
            if (jobj == null) jobj = new JObject();
            var result = await ServerController.MES_To_AGV_From_WEB_Test(headUrl + "MES_To_AGV_From_WEB_Test", jobj.ToString());
            return new HttpResponseMessage
            {
                Content = new StringContent(result, Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// AGV与MES站点交互
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<HttpResponseMessage> AGV_To_MES_AgvPass([FromBody] JObject jobj)
        {
            if (jobj == null) jobj = new JObject();
            var result = await ServerController.AGV_To_MES_AgvPass(headUrl + "AGV_To_MES_AgvPass", jobj.ToString());
            return new HttpResponseMessage
            {
                Content = new StringContent(result, Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
    }
} 
