package com.yc.ship.module.product.dal.mysql.productSpu;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.product.controller.admin.productSpu.spuVO.ProductSpuPageReqVO;
import com.yc.ship.module.product.controller.admin.productSpu.spuVO.ProductSpuRespVO;
import com.yc.ship.module.product.controller.admin.productSpu.spuVO.ProductSpuSimpleVO;
import com.yc.ship.module.product.dal.dataobject.productSpu.ProductSpuDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 产品基础信息 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {

    IPage<ProductSpuRespVO> selectPage2(IPage<ProductSpuRespVO> iPage, @Param("param") ProductSpuPageReqVO pageReqVO);

    IPage<ProductSpuRespVO> selectAppletPage(IPage<ProductSpuRespVO> iPage, @Param("param") ProductSpuPageReqVO pageReqVO);

    IPage<ProductSpuRespVO> selectPlatSpuList(IPage<ProductSpuRespVO> iPage, @Param("param") ProductSpuPageReqVO pageReqVO);

    @TenantIgnore
    default ProductSpuDO selectOneWithoutTenant(Long id) {
        return selectOne(ProductSpuDO::getId, id);
    }

    List<ProductSpuDO> getProductSpuListByStatus(@Param("categoryId") Long categoryId,@Param("channelId") Integer channelId, @Param("status") Integer status);

    List<Map<String,Object>> getProductSpuList(@Param("categoryIds") Collection<Long> categoryIds);

    default List<ProductSpuDO> selectListByCategory(Long cateId){
        return selectList(new LambdaQueryWrapperX<ProductSpuDO>()
                .eq(ProductSpuDO::getCategoryId,cateId)
        );
    }

    List<ProductSpuSimpleVO> selectSimpleList(@Param("param")ProductSpuPageReqVO reqVO);
    List<ProductSpuSimpleVO> listAllSpu();
    List<ProductSpuSimpleVO> listByShipId(@Param("shipId")Long shipId);
    @TenantIgnore
    List<ProductSpuSimpleVO> selectPlatSimpleList(@Param("param")ProductSpuPageReqVO reqVO);

    @TenantIgnore
    List<ProductSpuSimpleVO> getPlatProductlist(@Param("productId")Long productId);

    default List<ProductSpuDO> selectProductSpuListByCategory(Long categoryId) {
        LambdaQueryWrapperX<ProductSpuDO> queryWrapperX = new LambdaQueryWrapperX();
        queryWrapperX.select(ProductSpuDO::getId,ProductSpuDO::getCategoryId,ProductSpuDO::getProductName)
                .eq(ProductSpuDO::getCategoryId,categoryId).eq(ProductSpuDO::getIsUse,1);
        return selectList(queryWrapperX);
    }

    @TenantIgnore
    List<Map<String,Object>> getPlatProductIdsById(@Param("productId") Long id);

}
