package cn.newfeifan.mall.module.distri.dal.mysql.ptprofitlog;


import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofitlog.PtProfitLogDO;
import org.apache.ibatis.annotations.Mapper;
import cn.newfeifan.mall.module.distri.controller.app.ptprofitlog.vo.*;

import java.util.Arrays;
import java.util.List;

import static cn.newfeifan.mall.module.distri.enums.CaclEnum.*;

/**
 * 平台利润记录 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface PtProfitLogMapper extends BaseMapperX<PtProfitLogDO> {

    default PageResult<PtProfitLogDO> selectPage(PtProfitLogPageReqVO reqVO) {
        LambdaQueryWrapperX<PtProfitLogDO> queryWrapper = new LambdaQueryWrapperX<PtProfitLogDO>()
                .eqIfPresent(PtProfitLogDO::getProfitType, reqVO.getProfitType())
                .eqIfPresent(PtProfitLogDO::getAmount, reqVO.getAmount())
                .eqIfPresent(PtProfitLogDO::getAfterAmount, reqVO.getAfterAmount())
                .eqIfPresent(PtProfitLogDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(PtProfitLogDO::getPercentTemplate, reqVO.getPercentTemplate())
                .eqIfPresent(PtProfitLogDO::getGenerateUserId, reqVO.getGenerateUserId())
                .orderByDesc(PtProfitLogDO::getCreateTime)
                .orderByDesc(PtProfitLogDO::getId);


        return selectPage(reqVO, queryWrapper);
    }

    default PageResult<PtProfitLogDO> getMaxAmountPage(PtProfitLogPageReqVO pageReqVO) {
        List<Integer> profitStatus = Arrays.asList(
                DIRECT_REFERRAL_QUOTA.getType(),
                RECOMMENDED_PERSON_QUOTA.getType(),
                SMALL_QUOTA_CRASH.getType(),
                ORDER_REFUND_INTEGRAL_ANCESTER.getType(),
                ORDER_REFUND_ORDER_PAY_FREEZE_HIGH_QUOTA.getType(),
                MANUAL_RETURN_INTEGRAL.getType());
        return selectPage(pageReqVO, new LambdaQueryWrapperX<PtProfitLogDO>()
                .eqIfPresent(PtProfitLogDO::getGenerateUserId, pageReqVO.getGenerateUserId())
                .inIfPresent(PtProfitLogDO::getProfitStatus, profitStatus)
                .orderByDesc(PtProfitLogDO::getCreateTime)
                .orderByDesc(PtProfitLogDO::getId)
        );
    }
}