using Khd.Core.Application.Interface;
using Khd.Core.Domain.Dto.webapi;
using Masuit.Tools;
using Masuit.Tools.Logging;
using Microsoft.AspNetCore.Mvc;
using System.Threading;

namespace Khd.Core.Api.Controllers
{
    [Route("wcs/[controller]")]
    [ApiController]
    public class RecieveRcsController : ControllerBase
    {
        private readonly IWcsTaskApplication _application;

        public RecieveRcsController(IWcsTaskApplication application)
        {
            _application = application;
        }

        /// <summary>
        /// 接收agv接收任务通知接口，三楼和五楼Agv接口
        /// </summary>
        /// <param name="agvCallbackDto"></param>
        /// <returns></returns>
        [HttpPost("agvCallback")]
        public ReponseagvCallbackDto agvCallback(agvCallbackDto agvCallbackDto)
        {
            LogManager.Info($"RecieveRcsController接口信息：{agvCallbackDto.ToJsonString()}");
            Thread.Sleep(500);
            return _application.AgvCallback(agvCallbackDto);

        }

        /// <summary>
        /// 接收agv接收任务通知接口，二楼Agv接口
        /// </summary>
        /// <param name="agvCallbackDto"></param>
        /// <returns></returns>
        [HttpPost("agvCallback2")]
        public ReponseagvCallbackDto agvCallback2(agvCallbackDto agvCallbackDto)
        {
            LogManager.Info($"RecieveRcsController接口信息：{agvCallbackDto.ToJsonString()}");
            Thread.Sleep(500);
            return _application.AgvCallback2(agvCallbackDto);

        }

        /// <summary>
        /// 背负式Agv通知任务完成
        /// </summary>
        /// <param name="agvCompeletedRequest"></param>
        /// <returns></returns>
        [HttpPost("agvComplete")]
        public AgvCompeletedResponse MesToAgvComplete(AgvCompeleted agvCompeletedRequest)
        {
            LogManager.Info($"agvComplete接口信息：{agvCompeletedRequest.ToJsonString()}");
            return _application.MesToAgvComplete(agvCompeletedRequest);
        }

        /// <summary>
        /// 原材料入口任务继续通知
        /// </summary>
        /// <param name="taskContinue"></param>
        /// <returns></returns>
        [HttpPost("taskContinue")]
        public AgvCompeletedResponse TaskContinue(TaskContinue taskContinue)
        {
            LogManager.Info($"TaskContinue 接口收到消息： {taskContinue}");
            return _application.TaskContinue(taskContinue);
        }

        /// <summary>
        /// 通知去翻转机的任务
        /// </summary>
        /// <param name="callMaterial"></param>
        /// <returns></returns>
        [HttpPost("callMaterial")]
        public ReponseMessage CallMaterial(CallMaterial callMaterial)
        {
            LogManager.Info($"CallMaterial 接口收到消息： {callMaterial.ToJsonString()}");
            return _application.CallMaterial(callMaterial);
        }

        [HttpPost("AgvTaskComplete")]
        public ReponseMessage AGVTaskComplete()
        {
            LogManager.Info($"AgvTaskComplete 接口收到消息");
            return _application.AGVTaskComplete();
        }

        /// <summary>
        /// 通知agv停止或启动
        /// </summary>
        /// <param name="agvStopOrStart"></param>
        /// <returns></returns>
        [HttpPost("AgvStopOrStart")]
        public ReponseMessage AGVStopOrStart(CallAgvStopOrStart agvStopOrStart)
        {
            LogManager.Info($"AGVStopOrStart 接口收到消息： {agvStopOrStart.ToJsonString()}");
            return _application.CallAgvStopOrStart(agvStopOrStart);
        }

        /// <summary>
        /// 取消CTU预调度接口，WPF界面使用
        /// </summary>
        /// <returns></returns>
        [HttpPost("CancelPreScheduling")]
        public ReponseMessage CancelPreScheduling()
        {
            LogManager.Info($"CancelPreScheduling 接口收到消息");
            return _application.CancelPreScheduling();
        }

    }
}