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("请求参数错误");
        List<TPickGoods>? result = pickingGoodsDao.SelectPickTask(vehicleNo);
        if(result == default) 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 (PickCompleteDto pickCompleteDto in request)
        {
            var pickNum = pickCompleteDto.PickingNum;
            if(!pickNum.IsNumber()) pickNum = "0";
            pickData.Add((pickCompleteDto.VehicleNo, pickCompleteDto.GoodsId, Convert.ToDecimal(pickNum)));
        }
        bool updateResult = pickingGoodsDao.PickComplete(pickData);
        return updateResult ? MobileApiResponse.Success("完成") : MobileApiResponse.Fail("数据服务异常");
    }


}
