using Pms.Models;
using ProjectManagementSystem.Common.Models;
using System;
using System.Web.Http;
using System.Web.Http.Results;
using System.Linq;
using System.Collections.Generic;
using System.Net.Http;
using System.IO;
using System.Net.Http.Headers;
using System.Net;
using ProjectManagementSystem.Common.Core;
using System.Runtime.CompilerServices;
using System.Web.Http.Description;
using ProjectManagementSystem.WebApi.Filters;
using ProjectManagementSystem.Common.Service;

namespace ProjectManagementSystem.WebApi.Controller
{
    
    public class PmsController : ApiController
    {
        private IPmsTaskService taskService = PmsTaskService.Instance;

        [GlobalActionFilter]
        [ValidateModel]
        [HttpPost]
        public WebMgrResponse TaskAdd([FromBody] PmsTaskInfoDto dataDto)
        {
            return taskService.TaskAdd(dataDto);
        }

        [GlobalActionFilter]
        [ValidateModel]
        [HttpPost]
        public WebMgrResponse TaskAppointment([FromBody] PmsTaskInfoDto dataDto)
        {
            return taskService.TaskAppointment(dataDto);
        }

        //[HttpPost]
        //public ResponseResult TransportTask([FromBody] RequestTransportTask taskInfo)
        //{
        //    return taskService.TransportTask(taskInfo);
        //}

        //[HttpPost]
        //public ResponseResult StoreStateChange([FromBody] RequestStoreStateChange data)
        //{
        //    return taskService.StoreStateChange(data);
        //}

        [HttpPost]
        public WebMgrResponse ReleaseAgv([FromBody] ReleaseAgvDto data)
        {
            return taskService.ReleaseAgv(data);
        }

        [HttpGet]
        public WebMgrResponse GetAllLocationProperty()
        {
            return taskService.GetAllLocationProperty();
        }

        [GlobalActionFilter]
        [ValidateModel]
        [HttpPost]
        public WebMgrResponse UpdateLocationProperty(LocationPropertyDto data)
        {
            return taskService.UpdateLocationProperty(data);
        }

        [GlobalActionFilter]
        [HttpPost]
        public ResponseData GenAgvSchedulingTask([FromBody] RequestGenAgvSchedulingTask taskInfo)
        {
            if (!ModelState.IsValid)
            {
                ResponseData responseData = new ResponseData();
                responseData.code = "1";
                responseData.reqCode = taskInfo.reqCode;
                responseData.message = ModelState.Values.First().Errors[0].ErrorMessage;

                return responseData;
            }

            return taskService.GenAgvSchedulingTask(taskInfo);
        }
    }
}
