package cn.iocoder.yudao.module.product.dal.mysql.storecategory;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.storecategory.vo.StoreProductCategoryListReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.storecategory.StoreProductCategoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 商品分类 Mapper
 *
 * @author yshop
 */
@Mapper
public interface StoreProductCategoryMapper extends BaseMapperX<StoreProductCategoryDO> {

    default List<StoreProductCategoryDO> selectList(StoreProductCategoryListReqVO listReqVO) {
        return selectList(new LambdaQueryWrapperX<StoreProductCategoryDO>()
                .likeIfPresent(StoreProductCategoryDO::getName, listReqVO.getName())
                .likeIfPresent(StoreProductCategoryDO::getShopName, listReqVO.getShopName())
                .eqIfPresent(StoreProductCategoryDO::getShopId, listReqVO.getShopId())
                .orderByDesc(StoreProductCategoryDO::getId));
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(StoreProductCategoryDO::getParentId, parentId);
    }

    default List<StoreProductCategoryDO> selectListByStatus(Integer status, Integer shopId) {
        return selectList(new LambdaQueryWrapperX<StoreProductCategoryDO>()
                .eqIfPresent(StoreProductCategoryDO::getStatus, status)
                .eqIfPresent(StoreProductCategoryDO::getShopId, shopId)
                .orderByDesc(StoreProductCategoryDO::getId));
    }

}
