package com.jeequan.jeepay.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.service.mapper.MchPayInterfaceConfigMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class MchPayInterfaceConfigService extends ServiceImpl<MchPayInterfaceConfigMapper, com.jeequan.jeepay.db.entity.MchPayInterfaceConfig> {

    public LambdaQueryChainWrapper<com.jeequan.jeepay.db.entity.MchPayInterfaceConfig> wrapperByIsvNo(String isvNo, String ifCode) {
        return wrapperByIsvNo(isvNo, ifCode, null);
    }

    public LambdaQueryChainWrapper<com.jeequan.jeepay.db.entity.MchPayInterfaceConfig> wrapperByIsvNo(String isvNo, String ifCode, String status) {
        return lambdaQuery()
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoType, CS.SYS_ROLE_TYPE.ISV)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoId, isvNo)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getIfCode, ifCode)
                .eq(!ObjectUtils.isEmpty(status), com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getState, status);
    }

    public LambdaQueryChainWrapper<com.jeequan.jeepay.db.entity.MchPayInterfaceConfig> wrapperByAgentNo(String agentNo, String ifCode) {
        return wrapperByAgentNo(agentNo, ifCode, null);
    }

    public LambdaQueryChainWrapper<com.jeequan.jeepay.db.entity.MchPayInterfaceConfig> wrapperByAgentNo(String agentNo, String ifCode, String status) {
        return lambdaQuery()
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoType, CS.SYS_ROLE_TYPE.ISV)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoId, agentNo)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getIfCode, ifCode)
                .eq(!ObjectUtils.isEmpty(status), com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getState, status);
    }

    public com.jeequan.jeepay.db.entity.MchPayInterfaceConfig get(String infoType, String infoId, String ifCode) {
        return lambdaQuery().eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoId, infoId)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getInfoType, infoType)
                .eq(com.jeequan.jeepay.db.entity.MchPayInterfaceConfig::getIfCode, ifCode)
                .one();
    }
}
