using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.MaterielEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Core;
using WIDESEA_Core.Attributes;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.ERP;
using WIDESEA_External.ERPService;
using WIDESEA_External.Model;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundService;
using WIDESEA_IOutboundService;
using WIDESEA_Model.Models;
using static WIDESEA_DTO.ErpResponseContent;
namespace WIDESEA_WMSServer.Controllers.ERP
{
    /// 
    /// ERP接口
    /// 
    [Route("api/Erp")]
    [ApiController]
    public class ErpController : ControllerBase
    {
        private readonly IBasicService _basicService;
        private readonly IOutboundService _outboundService;
        private readonly IInboundService _inboundService;
        private readonly IInvokeERPService _invokeERPService;
        public ErpController(IBasicService basicService, IOutboundService outboundService, IInboundService inboundService,
            IInvokeERPService invokeERPService)
        {
            _basicService = basicService;
            _outboundService = outboundService;
            _inboundService = inboundService;
            _invokeERPService = invokeERPService;
        }
        /// 
        /// 接收ERP采购单信息
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceivePurchaseOrder"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceivePurchaseOrder([FromBody] Root model)
        {
            WebResponseContent content = _inboundService.PurchaseOrderService.ReceivePurchaseOrder(model.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 接收ERP仓库员工和质检员工数据
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceiveUser"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceiveUser([FromBody] Root model)
        {
            WebResponseContent content = _basicService.UserInfoService.ReceiveUser(model.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 接收ERP供应商信息
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceiveSupplier"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceiveSupplier([FromBody] Root model)
        {
            WebResponseContent content = _basicService.SupplierInfoService.ReceiveSupplier(model.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 接收ERP物料信息
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceiveMaterial"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceiveMaterial([FromBody] Root model)
        {
            WebResponseContent content = _basicService.MaterielInfoService.ReceiveMaterial(model.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 接收ERP客户信息
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceiveCustomer"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceiveCustomer([FromBody] Root model)
        {
            WebResponseContent content = _basicService.CustomerInfoService.ReceiveCustomer(model.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 接收ERP出库单信息
        /// 
        /// 
        /// 
        [HttpPost, Route("ReceiveOutOrder"), AllowAnonymous, MethodParamsValidate]
        public ErpResponseContent ReceiveOutOrder([FromBody] Root erpOutOrder)
        {
            WebResponseContent content = _outboundService.OutboundOrderService.ReceiveOutOrder(erpOutOrder.Content);
            if (content.Status) return Instance.OK();
            else return Instance.Error(content.Message);
        }
        /// 
        /// 推送ERP出库
        /// 
        /// 
        /// 
        [HttpPost, Route("InvokeOutStandardsApi"), AllowAnonymous]
        public string InvokeOutStandardsApi([FromBody] ERPIssueModel issueModel)
        {
            return _invokeERPService.InvokeOutStandardsApi(issueModel);
        }
    }
}