package co.yixiang.yshop.module.product.dal.mysql.campaigndetail;

import java.util.*;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.module.product.controller.admin.campaigninfo.vo.CampaignDataDetailPageReqVO;
import co.yixiang.yshop.module.product.controller.admin.campaigninfo.vo.CampaignDataDetailRespVO;
import co.yixiang.yshop.module.product.controller.app.campaigninfo.vo.AppCampaignSkuRespVO;
import co.yixiang.yshop.module.product.dal.dataobject.campaigndetail.CampaignDetailDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import co.yixiang.yshop.module.product.controller.admin.campaigndetail.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 营销活动明细 Mapper
 *
 * @author moxiangrong
 */
@Mapper
public interface CampaignDetailMapper extends BaseMapperX<CampaignDetailDO> {

    default PageResult<CampaignDetailDO> selectPage(CampaignDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CampaignDetailDO>()
                .eqIfPresent(CampaignDetailDO::getCampaignId, reqVO.getCampaignId())
                .eqIfPresent(CampaignDetailDO::getProductId, reqVO.getProductId())
                .eqIfPresent(CampaignDetailDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(CampaignDetailDO::getPrice, reqVO.getPrice())
                .eqIfPresent(CampaignDetailDO::getDiscount, reqVO.getDiscount())
                .eqIfPresent(CampaignDetailDO::getStock, reqVO.getStock())
                .eqIfPresent(CampaignDetailDO::getTotal, reqVO.getTotal())
                .betweenIfPresent(CampaignDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CampaignDetailDO::getId));
    }

    List<CampaignDataDetailRespVO> getCampaignDataDetail(Page page,
                                                         @Param("pageReqVO") CampaignDataDetailPageReqVO pageReqVO);

    default List<CampaignDetailDO> selectList(CampaignDetailExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CampaignDetailDO>()
                .eqIfPresent(CampaignDetailDO::getCampaignId, reqVO.getCampaignId())
                .eqIfPresent(CampaignDetailDO::getProductId, reqVO.getProductId())
                .eqIfPresent(CampaignDetailDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(CampaignDetailDO::getPrice, reqVO.getPrice())
                .eqIfPresent(CampaignDetailDO::getDiscount, reqVO.getDiscount())
                .eqIfPresent(CampaignDetailDO::getStock, reqVO.getStock())
                .eqIfPresent(CampaignDetailDO::getTotal, reqVO.getTotal())
                .betweenIfPresent(CampaignDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CampaignDetailDO::getId));
    }

    List<CampaignSkuDetailRespVO> getCampaignDetails(@Param("campaignId") Long campaignId);

    void deleteCampaignDetails(@Param("campaignId") Long campaignId);

    List<AppCampaignSkuRespVO> getCampaignSkus(@Param("productIds") List<Long> productIds);

}
