package cn.iocoder.hake.module.pay.dal.mysql.serviceregist;

import cn.iocoder.hake.framework.common.pojo.PageResult;
import cn.iocoder.hake.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.hake.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.hake.module.pay.dal.dataobject.serviceregist.ServiceRegistDO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo.*;

/**
 * 商户服务注册 Mapper
 *
 * @author hake
 */
@Mapper
public interface ServiceRegistMapper extends BaseMapperX<ServiceRegistDO> {

    default PageResult<ServiceRegistDO> selectPage(ServiceRegistPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ServiceRegistDO>()
                .eqIfPresent(ServiceRegistDO::getAppId, reqVO.getAppId())
                .likeIfPresent(ServiceRegistDO::getAppName, reqVO.getAppName())
                .eqIfPresent(ServiceRegistDO::getChannelId, reqVO.getChannelId())
                .eqIfPresent(ServiceRegistDO::getMchNo, reqVO.getMchNo())
                .likeIfPresent(ServiceRegistDO::getMchName, reqVO.getMchName())
                .eqIfPresent(ServiceRegistDO::getState, reqVO.getState())
                .eqIfPresent(ServiceRegistDO::getAppPubKey, reqVO.getAppPubKey())
                .eqIfPresent(ServiceRegistDO::getAppSecret, reqVO.getAppSecret())
                .eqIfPresent(ServiceRegistDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(ServiceRegistDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ServiceRegistDO::getId));
    }

    default ServiceRegistDO selectByCondition(String appId, String channelId, String mchNo) {
        return selectOne(Wrappers.<ServiceRegistDO>lambdaQuery()
                .eq(ServiceRegistDO::getAppId, appId)
                .eq(ServiceRegistDO::getChannelId, channelId)
                .eq(ServiceRegistDO::getMchNo, mchNo));
    }

}