const vatClient = require("./vatClient")
const wangwenClient = require("./wangwenClient")
const pannongClient = require("./pannongClient")
const guangboClient = require("./guangboClient")
const gongshangClient = require("./gongshangClient")
const commonVatClient = require("./commonVatClient")


const system = require("../../system");


/**
 * 根据产品类型选择不同的方法
 * @param {*} type 
 */
function getClientByType(type) {
    switch (type) {
        case system.SERVICECODE.ICP:
        case system.SERVICECODE.EDI:
            return vatClient.getInstance();
        case system.SERVICECODE.WANGWEN:
            return wangwenClient.getInstance();
        case system.SERVICECODE.PANNONG:
            return pannongClient.getInstance();
        case system.SERVICECODE.GUANGBO:
            return guangboClient.getInstance();
        case system.SERVICECODE.COMPANYCASE:
        case system.SERVICECODE.OPENBANKACCOUNTCASE:
        case system.SERVICECODE.TAXCASE:
        case system.SERVICECODE.REGADDRCASE1:
        case system.SERVICECODE.AGENTCASE1:
            return gongshangClient.getInstance();
        default:
            throw new Error("无此产品类型");
    }
}

/**
 * 根据产品类型、渠道选择不同的方法
 * @param {*} type
 * @param {*} channel
 */
function getClientByTypeAndChannel(type,channel) {
    switch (type) {
        case system.SERVICECODE.ICP:
        case system.SERVICECODE.EDI:
        case system.SERVICECODE.IDC:
        case system.SERVICECODE.ISP:
        case system.SERVICECODE.SP:
        case system.SERVICECODE.CCL:
        case system.SERVICECODE.CDN:
        case system.SERVICECODE.NCBI_AM:
        case system.SERVICECODE.NCBI_lB:
        case system.SERVICECODE.BC:
        case system.SERVICECODE.IEP:
        case system.SERVICECODE.HRSL:
        case system.SERVICECODE.LDP:
        case system.SERVICECODE.RTPPOL:
        case system.SERVICECODE.PBL_R:
        case system.SERVICECODE.PBL_W:
        case system.SERVICECODE.CPL:
        case system.SERVICECODE.ISO9001:
        case system.SERVICECODE.ISO14001:
        case system.SERVICECODE.ISO27001:
        case system.SERVICECODE.ISO20000:
        case system.SERVICECODE.ISO45001:
        case system.SERVICECODE.IONHTE:
        case system.SERVICECODE.SISSM:
        case system.SERVICECODE.SSGEI:
        case system.SERVICECODE.DSCC:
        case system.SERVICECODE.HTACS:
        case system.SERVICECODE.BL_TMD:
        case system.SERVICECODE.BF_TMD:
        case system.SERVICECODE.IDISL_B:
        case system.SERVICECODE.IDISL_NB:
        case system.SERVICECODE.LPE_2:
        case system.SERVICECODE.LPE_3: //, system.SERVICECODE.EDI
            if([system.SERVICECODE.ICP,system.SERVICECODE.EDI].includes(type) && ['aliCloud','zc360','baidu','ename'].includes(channel)){ // 这4个渠道的icp、edi走老接口
                return vatClient.getInstance();
            }else{
                return commonVatClient.getInstance();
            }
        case system.SERVICECODE.WANGWEN:
            return wangwenClient.getInstance();
        case system.SERVICECODE.PANNONG:
            return pannongClient.getInstance();
        case system.SERVICECODE.GUANGBO:
            return guangboClient.getInstance();
        case system.SERVICECODE.COMPANYCASE:
        case system.SERVICECODE.OPENBANKACCOUNTCASE:
        case system.SERVICECODE.TAXCASE:
        case system.SERVICECODE.REGADDRCASE1:
        case system.SERVICECODE.AGENTCASE1:
            return gongshangClient.getInstance();
        default:
            throw new Error("无此产品类型");
    }
}

module.exports = {
    getClientByType,
    getClientByTypeAndChannel
}