package cn.iocoder.yudao.module.basic.dal.mysql.goodsinfo;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.basic.controller.admin.goodsinfo.vo.GoodsInfoForTransferRespVO;
import cn.iocoder.yudao.module.basic.controller.admin.goodsinfo.vo.GoodsInfoListReqVO;
import cn.iocoder.yudao.module.basic.controller.admin.goodsinfo.vo.GoodsInfoPageReqVO;
import cn.iocoder.yudao.module.basic.controller.admin.goodsinfo.vo.GoodsInfoRespVO;
import cn.iocoder.yudao.module.basic.dal.dataobject.goodsinfo.GoodsInfoDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 商品 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface GoodsInfoMapper extends BaseMapperX<GoodsInfoDO> {

    default PageResult<GoodsInfoDO> selectPage(GoodsInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GoodsInfoDO>()
                .likeIfPresent(GoodsInfoDO::getGoodsName, reqVO.getGoodsName())
                .eqIfPresent(GoodsInfoDO::getGoodsId, reqVO.getGoodsId())
                .eqIfPresent(GoodsInfoDO::getGoodsType, reqVO.getGoodsType())
                .eqIfPresent(GoodsInfoDO::getGoodsTypeId, reqVO.getGoodsTypeId())
                .eqIfPresent(GoodsInfoDO::getIsBaseUnit, reqVO.getIsBaseUnit())
                .eqIfPresent(GoodsInfoDO::getGoodsSpecs, reqVO.getGoodsSpecs())
                .eqIfPresent(GoodsInfoDO::getGoodsUnitId, reqVO.getGoodsUnitId())
                .eqIfPresent(GoodsInfoDO::getConversionValue,reqVO.getConversionValue())
                .eqIfPresent(GoodsInfoDO::getGoodsImgUrl, reqVO.getGoodsImgUrl())
                .eqIfPresent(GoodsInfoDO::getShelfLife, reqVO.getShelfLife())
                .eqIfPresent(GoodsInfoDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(GoodsInfoDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(GoodsInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(GoodsInfoDO::getId));
    }

    default List<GoodsInfoDO> selectListQuery(GoodsInfoListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<GoodsInfoDO>()
                .eqIfPresent(GoodsInfoDO::getGoodsName, reqVO.getGoodsName())
                .eqIfPresent(GoodsInfoDO::getGoodsId, reqVO.getGoodsId())
                .eqIfPresent(GoodsInfoDO::getGoodsType, reqVO.getGoodsType())
                .eqIfPresent(GoodsInfoDO::getGoodsTypeId, reqVO.getGoodsTypeId())
                .eqIfPresent(GoodsInfoDO::getIsBaseUnit, reqVO.getIsBaseUnit())
                .eqIfPresent(GoodsInfoDO::getGoodsSpecs, reqVO.getGoodsSpecs())
                .eqIfPresent(GoodsInfoDO::getGoodsUnitId, reqVO.getGoodsUnitId())
                .eqIfPresent(GoodsInfoDO::getConversionValue,reqVO.getConversionValue())
                .eqIfPresent(GoodsInfoDO::getGoodsImgUrl, reqVO.getGoodsImgUrl())
                .eqIfPresent(GoodsInfoDO::getShelfLife, reqVO.getShelfLife())
                .eqIfPresent(GoodsInfoDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .eqIfPresent(GoodsInfoDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(GoodsInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(GoodsInfoDO::getId));
    }

//    IPage<GoodsInfoDO> selectPageByInfo(IPage<GoodsInfoDO> page, @Param(Constants.WRAPPER) Wrapper<GoodsInfoDO> queryWrapper);

    IPage<GoodsInfoDO> selectGoodsInfoById(Page<GoodsInfoDO> page,
                                           @Param("goodsName")  String goodsName,
                                           @Param("goodsId")  String goodsId,
                                           @Param("goodsUnitId") Long goodsUnitId,
                                           @Param("belongBusinessName")  String belongBusinessName);

    List<GoodsInfoRespVO> getGoodsListByBusinessInfoId(@Param("businessInfoId") Long businessInfoId);

    List<GoodsInfoForTransferRespVO> queryListOfMiniResult(@Param("belongBusinessId") Long belongBusinessId);

    GoodsInfoRespVO getByGoodsId(@Param("goodsId") String goodsId);
}
