package com.jeequan.jeepay.core.model.params;

import com.alibaba.fastjson.JSON;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.model.params.aliaqf.AliaqfIsvParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvParams;
import com.jeequan.jeepay.core.model.params.allinpay.AllinpayIsvParams;
import com.jeequan.jeepay.core.model.params.bcmpay.BcmpayIsvParams;
import com.jeequan.jeepay.core.model.params.cloudpay.CloudpayIsvParams;
import com.jeequan.jeepay.core.model.params.demomockpay.DemomockpayIsvParams;
import com.jeequan.jeepay.core.model.params.dgpay.DgpayIsvParams;
import com.jeequan.jeepay.core.model.params.easypay.EasypayIsvParams;
import com.jeequan.jeepay.core.model.params.epspay.EpspayIsvParams;
import com.jeequan.jeepay.core.model.params.fbpay.FbpayIsvParams;
import com.jeequan.jeepay.core.model.params.fuioupay.FuioupayIsvParams;
import com.jeequan.jeepay.core.model.params.hkpay.HkpayIsvParams;
import com.jeequan.jeepay.core.model.params.hmpay.HmpayIsvParams;
import com.jeequan.jeepay.core.model.params.hnapay.HnapayIsvParams;
import com.jeequan.jeepay.core.model.params.icbcpay.IcbcpayIsvParams;
import com.jeequan.jeepay.core.model.params.kdbpay.KdbpayIsvParams;
import com.jeequan.jeepay.core.model.params.kqpay.KqpayIsvParams;
import com.jeequan.jeepay.core.model.params.leshuapay.LeshuapayIsvParams;
import com.jeequan.jeepay.core.model.params.lklpay.LklpayIsvParams;
import com.jeequan.jeepay.core.model.params.lklsb2bpay.Lklsb2bpayIsvParams;
import com.jeequan.jeepay.core.model.params.lklspay.LklspayIsvParams;
import com.jeequan.jeepay.core.model.params.lmspay.LmspayIsvParams;
import com.jeequan.jeepay.core.model.params.mbpay.MbpayIsvParams;
import com.jeequan.jeepay.core.model.params.pfpay.PfpayIsvParams;
import com.jeequan.jeepay.core.model.params.pmpay.PmpayIsvParams;
import com.jeequan.jeepay.core.model.params.ruipay.RyxpayIsvParams;
import com.jeequan.jeepay.core.model.params.sftpay.SftpayIsvParams;
import com.jeequan.jeepay.core.model.params.shengpay.ShengpayIsvParams;
import com.jeequan.jeepay.core.model.params.sqbpay.SqbpayIsvParams;
import com.jeequan.jeepay.core.model.params.sxfpay.SxfpayIsvParams;
import com.jeequan.jeepay.core.model.params.terpay.TerpayIsvParams;
import com.jeequan.jeepay.core.model.params.umhspay.UmhspayIsvParams;
import com.jeequan.jeepay.core.model.params.umpay.UmpayIsvParams;
import com.jeequan.jeepay.core.model.params.utmpay.UtmpayIsvParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayIsvParams;
import com.jeequan.jeepay.core.model.params.ysf.YsfpayIsvParams;
import com.jeequan.jeepay.core.model.params.yspay.YspayIsvParams;
import com.jeequan.jeepay.core.model.params.zftpay.ZftpayIsvParams;
import com.jeequan.jeepay.core.utils.JeepayKit;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 抽象类 isv参数定义
 *
 * @author terrfly
 *
 * @date 2021/6/8 16:33
 * @modify ZhuXiao
 */
@Data
public abstract class IsvParams {

    /** 结算方式 1- T1  2-D1 3-D0 */
    protected String settType;

    private static final Map<String, Class<? extends IsvParams>> isvParamMap = new HashMap<>();

    static {
        isvParamMap.put(CS.IF_CODE.WXPAY, WxpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.ALIPAY, AlipayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.YSFPAY, YsfpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.SHENGPAY, ShengpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.ZFTPAY, ZftpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.SFTPAY, SftpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.HMPAY, HmpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.FUIOUPAY, FuioupayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.LKLPAY, LklpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.LKLSPAY, LklspayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.LKLSB2BPAY, Lklsb2bpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.FBPAY, FbpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.DGPAY, DgpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.PFPAY, PfpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.UTMPAY, UtmpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.SQBPAY, SqbpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.YSPAY, YspayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.ALLINPAY, AllinpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.MBPAY, MbpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.RYXPAY, RyxpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.TERPAY, TerpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.PMPAY, PmpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.UMPAY, UmpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.CLOUDPAY, CloudpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.HKPAY, HkpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.HNAPAY, HnapayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.BCMPAY, BcmpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.ICBCPAY, IcbcpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.EASYPAY, EasypayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.LMSPAY, LmspayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.LESHUAPAY, LeshuapayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.ALIAQF, AliaqfIsvParams.class);
        isvParamMap.put(CS.IF_CODE.SXFPAY, SxfpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.EPSPAY, EpspayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.DEMOMOCKPAY, DemomockpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.UMHSPAY, UmhspayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.KDBPAY, KdbpayIsvParams.class);
        isvParamMap.put(CS.IF_CODE.KQPAY, KqpayIsvParams.class);
    }

    public static IsvParams factory(String ifCode, String paramsStr) {
        ifCode = JeepayKit.getIfCodeOrigin(ifCode);

        Class<? extends IsvParams> aClass = isvParamMap.get(ifCode);

        return JSON.parseObject(paramsStr, aClass);
    }

    /**
     * 用于对账单下载，根据支付参数配置  获取渠道唯一渠道商号
     * 渠道是通过渠道商下载对账单时，需添加对应渠道商户号的获取
     */
    public static String getChannelIsvNo(String ifCode, IsvParams isvParams) {

        ifCode = JeepayKit.getIfCodeOrigin(ifCode);

        if (isvParams == null) {
            return null;
        } else if (CS.IF_CODE.WXPAY.equals(ifCode)) {
            return ((WxpayIsvParams) isvParams).getMchId();
        } else if (CS.IF_CODE.SHENGPAY.equals(ifCode)) {
            return ((ShengpayIsvParams) isvParams).getMchId();
        } else if (CS.IF_CODE.SXFPAY.equals(ifCode)) {
            return ((SxfpayIsvParams) isvParams).getOrgId();
        }
        return null;
    }

    /**
     * 敏感数据脱敏
     */
    public abstract String deSenData();

    private Long altId;
}
