using WmsMobileServe.Annotation;
using WmsMobileServe.ApiServe.Mobile.Dto;
using WmsMobileServe.ApiServe.Mobile.Vo;
using WmsMobileServe.DataBase.Base.Dao;
using WmsMobileServe.DataBase.Base.Po;
using WmsMobileServe.Utils;

namespace WmsMobileServe.ApiServe.Mobile.Service;


[Component]
public class PickService(TPickingGoodsDao pickingGoodsDao)
{

    public MobileApiResponse<List<TPickGoods>> GetPickTask(string? vehicleNo)
    {
        if (string.IsNullOrWhiteSpace(vehicleNo)) return MobileApiResponse<List<TPickGoods>>.Fail("请求参数错误");
        vehicleNo = vehicleNo.Trim();
        var result = pickingGoodsDao.SelectPickTask(vehicleNo);
        if(result == null) return MobileApiResponse<List<TPickGoods>>.Fail("数据服务异常");
        if(result.Count < 1) return MobileApiResponse<List<TPickGoods>>.Fail("该托盘没有待检货物");
        return MobileApiResponse<List<TPickGoods>>.Success("成功", result);
    }



    public MobileApiResponse PickComplete(List<PickCompleteDto> request)
    {
        if (request.Count < 1) return MobileApiResponse.Fail("请求参数错误");
        List<(string? vehicleNo, string? goodsId, decimal? pickingNum)> pickData = [];
        foreach (var pickCompleteDto in request)
        {
            var pickNum = pickCompleteDto.PickingNum;
            if(!pickNum.IsNumber()) pickNum = "0";
            pickData.Add((pickCompleteDto.VehicleNo, pickCompleteDto.GoodsId, Convert.ToDecimal(pickNum)));
        }
        var updateResult = pickingGoodsDao.PickComplete(pickData);
        return updateResult ? MobileApiResponse.Success("完成") : MobileApiResponse.Fail("数据服务异常");
    }


}
