package com.lideeyunji.service.system.mapper;

import com.lideeyunji.tool.framework.common.pojo.PageResult;
import com.lideeyunji.tool.framework.mybatis.core.mapper.BaseMapperX;
import com.lideeyunji.tool.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.lideeyunji.service.system.controller.vo.oauth2.client.OAuth2ClientPageReqVO;
import com.lideeyunji.service.system.entity.OAuth2ClientDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;


/**
 * OAuth2 客户端 Mapper
 *
 * @author 金灯剑客
 */
@Mapper
public interface OAuth2ClientMapper extends BaseMapperX<OAuth2ClientDO> {

    default PageResult<OAuth2ClientDO> selectPage(OAuth2ClientPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OAuth2ClientDO>()
                .likeIfPresent(OAuth2ClientDO::getName, reqVO.getName())
                .eqIfPresent(OAuth2ClientDO::getStatus, reqVO.getStatus())
                .neIfPresent(OAuth2ClientDO::getClientId, "default")
                .inIfPresent(OAuth2ClientDO::getId, reqVO.getIds())
                .orderByDesc(OAuth2ClientDO::getId));
    }

    default OAuth2ClientDO selectByClientId(String clientId) {
        return selectOne(OAuth2ClientDO::getClientId, clientId);
    }

    default List<OAuth2ClientDO> selectEnableList() {
        return selectList(new LambdaQueryWrapperX<OAuth2ClientDO>()
                .eq(OAuth2ClientDO::getStatus, 0));
    }

}
