package cn.ey.biz.module.system.dal.mapper.appuser;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.framework.mybatis.core.mapper.BaseMapperX;
import cn.ey.biz.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ey.biz.module.system.api.oauth2.dto.OAuth2AccessTokenClientCreateReqDTO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserPageReqVO;
import cn.ey.biz.module.system.dal.dataobject.appuser.AppUserDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 应用用户 Mapper
 */
@Mapper
public interface AppUserMapper extends BaseMapperX<AppUserDO> {

    default AppUserDO selectOne(OAuth2AccessTokenClientCreateReqDTO reqDTO) {
        return selectOne(new LambdaQueryWrapperX<AppUserDO>()
                .eqIfPresent(AppUserDO::getAppId, reqDTO.getAppId())
                .eqIfPresent(AppUserDO::getAppSecret, reqDTO.getAppSecret()));
    }

    default PageResult<AppUserDO> selectPage(AppUserPageReqVO reqVO) {
        LambdaQueryWrapperX<AppUserDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(AppUserDO::getDeleted, false)
                .eqIfPresent(AppUserDO::getAppId, reqVO.getAppId())
                .orderByDesc(AppUserDO::getId);
        return selectPage(reqVO, queryWrapperX);
    }

}
