package com.fq.channel.sdk.core;

import android.content.Context;

import com.fq.channel.sdk.base.interfaces.PluginResultHandler;
import com.fq.channel.sdk.base.utils.ResourceCfg;
import com.fq.channel.sdk.core.invoke.ApiPlugin;

import java.util.Map;

/**
 * @Description: 核心层对外API
 *
 * @Author: FLuty
 * @CreateDate: 2020/3/24 17:59
 */
public class JointManager {
    private static final String TAG = "JointManager";

    private volatile static JointManager uniqueInstance;

    private ResourceCfg mCfg;

    private JointManager() {}

    public static JointManager getInstance() {
        if (uniqueInstance == null) {
            synchronized (JointManager.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new JointManager();
                }
            }
        }
        return uniqueInstance;
    }

    public void initCfgConfigFile(Context mContext) {
        if (null == mCfg) {
            mCfg = new ResourceCfg(mContext);
        }
    }

    public void init(Context context,PluginResultHandler cb){
        initCfgConfigFile(context);//加载assets/cfg文件
        // 获取对应的ApiPlugin子类实例，并反射初始化SDK操作
        ApiPlugin.getInstace().init(context, cb);
    }

    public void login(Context context,PluginResultHandler cb){
        ApiPlugin.getInstace().login(context, cb);
    }

    public void pay(Context context, Map paymentInfo, PluginResultHandler cb){
        ApiPlugin.getInstace().pay(context, paymentInfo, cb);
    }

    public String getPluginSdkClassName() {
        return mCfg.getString("plugin_sdk_class_name");
    }

    public String getPluginName() {
        return mCfg.getString("plugin_name");
    }
}
