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

import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.model.params.adapay.AdapayNormalMchParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayNormalMchParams;
import com.jeequan.jeepay.core.model.params.allinpay.AllinpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.ccbpay.CcbpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.demomockpay.DemomockpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.dgpay.DgpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.fbpay.FbpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.joinpay.JoinpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.mbpay.MbpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.pfpay.PfpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.pmpay.PmpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.pppay.PpPayNormalMchParams;
import com.jeequan.jeepay.core.model.params.sandpay.SandpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.shengpay.ShengpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.sumapay.SumapayNormalMchParams;
import com.jeequan.jeepay.core.model.params.unionpay.UnionpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayNormalMchParams;
import com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams;
import com.jeequan.jeepay.core.utils.JeepayKit;

/*
 * 抽象类 普通商户参数定义
 *
 * @author terrfly
 *
 * @date 2021/6/8 16:33
 */
public abstract class NormalMchParams {

    public static NormalMchParams factory(String ifCode, String paramsStr){

        ifCode = JeepayKit.getIfCodeOrigin(ifCode);

        if(CS.IF_CODE.WXPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, WxpayNormalMchParams.class);
        }else if(CS.IF_CODE.ALIPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, AlipayNormalMchParams.class);
        }else if(CS.IF_CODE.XXPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, XxpayNormalMchParams.class);
        }else if(CS.IF_CODE.ADAPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, AdapayNormalMchParams.class);
        }else if(CS.IF_CODE.SHENGPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, ShengpayNormalMchParams.class);
        }else if(CS.IF_CODE.UNIONPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, UnionpayNormalMchParams.class);
        }else if(CS.IF_CODE.SANDPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, SandpayNormalMchParams.class);
        }else if (CS.IF_CODE.PPPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, PpPayNormalMchParams.class);
        }else if (CS.IF_CODE.PFPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, PfpayNormalMchParams.class);
        }else if (CS.IF_CODE.FBPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, FbpayNormalMchParams.class);
        }else if (CS.IF_CODE.DGPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, DgpayNormalMchParams.class);
        }else if (CS.IF_CODE.JOINPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, JoinpayNormalMchParams.class);
        }else if (CS.IF_CODE.ALLINPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, AllinpayNormalMchParams.class);
        }else if (CS.IF_CODE.MBPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, MbpayNormalMchParams.class);
        }else if (CS.IF_CODE.PMPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, PmpayNormalMchParams.class);
        }else if (CS.IF_CODE.CCBPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, CcbpayNormalMchParams.class);
        }else if (CS.IF_CODE.SUMAPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, SumapayNormalMchParams.class);
        }else if (CS.IF_CODE.DEMOMOCKPAY.equals(ifCode)){
            return JSONObject.parseObject(paramsStr, DemomockpayNormalMchParams.class);
        }
        return null;
    }

    /**
     *  用于普通商户对账单下载，根据支付参数配置  获取渠道唯一服务商号
     */
    public static String getChannelMchNo(String ifCode, NormalMchParams normalMchParams){

        ifCode = JeepayKit.getIfCodeOrigin(ifCode);

        if (normalMchParams == null) {
            return null;
        }else if(CS.IF_CODE.ALIPAY.equals(ifCode)){
            return ((AlipayNormalMchParams) normalMchParams).getAppId();
        }else if(CS.IF_CODE.WXPAY.equals(ifCode)){
            return ((WxpayNormalMchParams) normalMchParams).getMchId();
        }
        return null;
    }

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

}
