package co.yixiang.yshop.module.member.dal.mysql.userbill;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.module.member.controller.admin.userbill.vo.UserBillExportReqVO;
import co.yixiang.yshop.module.member.controller.admin.userbill.vo.UserBillPageReqVO;
import co.yixiang.yshop.module.member.controller.admin.userbill.vo.UserBillRespVO;
import co.yixiang.yshop.module.member.dal.dataobject.userbill.UserBillDO;
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 yshop
 */
@Mapper
public interface UserBillMapper extends BaseMapperX<UserBillDO> {

    default PageResult<UserBillDO> selectPage(UserBillPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserBillDO>()
                .eqIfPresent(UserBillDO::getUid, reqVO.getUid())
                .eqIfPresent(UserBillDO::getLinkId, reqVO.getLinkId())
                .eqIfPresent(UserBillDO::getPm, reqVO.getPm())
                .eqIfPresent(UserBillDO::getTitle, reqVO.getTitle())
                .eqIfPresent(UserBillDO::getCategory, reqVO.getCategory())
                .eqIfPresent(UserBillDO::getType, reqVO.getType())
                .eqIfPresent(UserBillDO::getNumber, reqVO.getNumber())
                .eqIfPresent(UserBillDO::getBalance, reqVO.getBalance())
                .eqIfPresent(UserBillDO::getMark, reqVO.getMark())
                .betweenIfPresent(UserBillDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(UserBillDO::getStatus, reqVO.getStatus())
                .orderByDesc(UserBillDO::getId));
    }

    default List<UserBillDO> selectList(UserBillExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserBillDO>()
                .eqIfPresent(UserBillDO::getUid, reqVO.getUid())
                .eqIfPresent(UserBillDO::getLinkId, reqVO.getLinkId())
                .eqIfPresent(UserBillDO::getPm, reqVO.getPm())
                .eqIfPresent(UserBillDO::getTitle, reqVO.getTitle())
                .eqIfPresent(UserBillDO::getCategory, reqVO.getCategory())
                .eqIfPresent(UserBillDO::getType, reqVO.getType())
                .eqIfPresent(UserBillDO::getNumber, reqVO.getNumber())
                .eqIfPresent(UserBillDO::getBalance, reqVO.getBalance())
                .eqIfPresent(UserBillDO::getMark, reqVO.getMark())
                .betweenIfPresent(UserBillDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(UserBillDO::getStatus, reqVO.getStatus())
                .orderByDesc(UserBillDO::getId));
    }

    default Long selectCount(UserBillPageReqVO reqVO) {
        return selectCount(new LambdaQueryWrapperX<UserBillDO>()
                .eqIfPresent(UserBillDO::getUid, reqVO.getUid())
                .eqIfPresent(UserBillDO::getLinkId, reqVO.getLinkId())
                .eqIfPresent(UserBillDO::getPm, reqVO.getPm())
                .eqIfPresent(UserBillDO::getTitle, reqVO.getTitle())
                .eqIfPresent(UserBillDO::getCategory, reqVO.getCategory())
                .eqIfPresent(UserBillDO::getType, reqVO.getType())
                .eqIfPresent(UserBillDO::getNumber, reqVO.getNumber())
                .eqIfPresent(UserBillDO::getBalance, reqVO.getBalance())
                .eqIfPresent(UserBillDO::getMark, reqVO.getMark())
                .betweenIfPresent(UserBillDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(UserBillDO::getStatus, reqVO.getStatus())
                .orderByDesc(UserBillDO::getId));
    }

    /**
     * 管理后台查询
     *
     * @param mpPage    分页
     * @param pageReqVO 条件
     * @return /
     */
    Page<UserBillRespVO> selectPageAdmin(IPage<UserBillRespVO> mpPage, @Param("param") UserBillPageReqVO pageReqVO);
}
