using Microsoft.AspNetCore.Mvc;
using WCS.BLL.Services.IService;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatInventoryDetail;
using WCS.Model.ApiModel.Stocktaking;
using WCS.Model.ApiModel.User;

namespace WCS.WebApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class StockTakingController : ControllerBase
    {
        public IStockTakingService _stockTakingService { get; set; }

        public IGenerateService _generateService { get; set; }

        public StockTakingController(IStockTakingService stockTakingService, IGenerateService generateService)
        {
            _stockTakingService = stockTakingService;
            _generateService = generateService;
        }

        [Route("SysStockTakingOrder")]
        [HttpPost(Name = "SysStockTakingOrder")]
        public async Task<ResponseBase> SysStockTakingOrder(SysStockTakingOrderRequest request)
        {
            //判断盘点单号是否已输入
            if (string.IsNullOrEmpty(request.StocktakingOrderNumber))
                request.StocktakingOrderNumber = await _generateService.generateStockTakingNumber();
            return await _stockTakingService.SysStockTakingOrder(request);
        }

        [Route("getStockTakingOrders")]
        [HttpPost(Name = "getStockTakingOrders")]
        public async Task<ResponseBase> getStockTakingOrders(GetStockTakingOrdersRequest request)
        {
            return await _stockTakingService.getStockTakingOrders(request);
        }

        [Route("getStockTakingOrdersByStatus")]
        [HttpPost(Name = "getStockTakingOrdersByStatus")]
        public async Task<ResponseBase> getStockTakingOrdersByStatus(GetStockTakingOrdersRequest request)
        {
            return await _stockTakingService.getStockTakingOrdersByStatus(request);
        }

        [Route("getStockTakingOrderMatDetail")]
        [HttpPost(Name = "getStockTakingOrderMatDetail")]
        public async Task<ResponseBase> getStockTakingOrderMatDetail(GetStockTakingOrderMatDetailRequest request)
        {
            return await _stockTakingService.getStockTakingOrderMatDetail(request);
        }

        [Route("startStockTakingOrder")]
        [HttpPost(Name = "startStockTakingOrder")]
        public async Task<ResponseBase> startStockTakingOrder(GetStockTakingOrderMatDetailRequest request)
        {
            return await _stockTakingService.startStockTakingOrder(request);
        }

        [Route("endStockTakingOrder")]
        [HttpPost(Name = "endStockTakingOrder")]
        public async Task<ResponseBase> endStockTakingOrder(GetStockTakingOrderMatDetailRequest request)
        {
            return await _stockTakingService.endStockTakingOrder(request);
        }


        [Route("queryMatInfoInStocktakingOrder")]
        [HttpPost(Name = "queryMatInfoInStocktakingOrder")]
        public async Task<ResponseBase> queryMatInfoInStocktakingOrder(QueryMatInfoInStocktakingOrderRequest request)
        {
            return await _stockTakingService.queryMatInfoInStocktakingOrder(request);
        }

        [Route("confirmStocktakingOrder")]
        [HttpPost(Name = "confirmStocktakingOrder")]
        public async Task<ResponseBase> confirmStocktakingOrder(ConfirmStocktakingOrderRequest request)
        {
            return await _stockTakingService.confirmStocktakingOrder(request);
        }

        [Route("commitStocktakingOrder")]
        [HttpPost(Name = "commitStocktakingOrder")]
        public async Task<ResponseBase> commitStocktakingOrder(GetStockTakingOrderMatDetailRequest request)
        {
            return await _stockTakingService.commitStockTakingOrder(request);
        }
    }
}
