package com.yolo.keyboard.dal.mysql.userinvitecodes;

import java.util.*;

import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
import com.yolo.keyboard.dal.dataobject.userinvitecodes.KeyboardUserInviteCodesDO;
import org.apache.ibatis.annotations.Mapper;
import com.yolo.keyboard.controller.admin.userinvitecodes.vo.*;

/**
 * 用户生成的邀请码表，用于邀请新用户注册/安装并建立邀请关系 Mapper
 *
 * @author ziin
 */
@Mapper
public interface KeyboardUserInviteCodesMapper extends BaseMapperX<KeyboardUserInviteCodesDO> {

    default PageResult<KeyboardUserInviteCodesDO> selectPage(KeyboardUserInviteCodesPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardUserInviteCodesDO>()
                .eqIfPresent(KeyboardUserInviteCodesDO::getCode, reqVO.getCode())
                .eqIfPresent(KeyboardUserInviteCodesDO::getOwnerUserId, reqVO.getOwnerUserId())
                .eqIfPresent(KeyboardUserInviteCodesDO::getStatus, reqVO.getStatus())
                .eqIfPresent(KeyboardUserInviteCodesDO::getCreatedAt, reqVO.getCreatedAt())
                .eqIfPresent(KeyboardUserInviteCodesDO::getExpiresAt, reqVO.getExpiresAt())
                .eqIfPresent(KeyboardUserInviteCodesDO::getMaxUses, reqVO.getMaxUses())
                .eqIfPresent(KeyboardUserInviteCodesDO::getUsedCount, reqVO.getUsedCount())
                .eqIfPresent(KeyboardUserInviteCodesDO::getOwnerTenantId, reqVO.getOwnerTenantId())
                .eqIfPresent(KeyboardUserInviteCodesDO::getOwnerSystemUserId, reqVO.getOwnerSystemUserId())
                .eqIfPresent(KeyboardUserInviteCodesDO::getInviteType, reqVO.getInviteType())
                .orderByDesc(KeyboardUserInviteCodesDO::getId));
    }

}