package com.fq.channel.sdk.base.constants;

import android.content.Context;


import com.fq.channel.sdk.base.utils.Utils;

import org.json.JSONObject;

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

/**
 * @Description:  读取渠道插件配置文件
 * @Author: FLuty
 * @CreateDate: 2020/3/24 15:18
 */
public class ResourceCfg {

	private String mFilePath = "fq_config/joint_cfg";

	private Map<String, Object> mData;

	public ResourceCfg(Context context) {
		mData = new HashMap<String, Object>();
		initCfg(context);
	}

	private void initCfg(Context context) {
		try {
			String st = Utils.readSimplelyFile(context.getAssets().open(mFilePath));
			JSONObject json = new JSONObject(st);
			Iterator<String> it = json.keys();
			while (it.hasNext()) {
				String key = it.next();
				mData.put(key, json.get(key));
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
	}

	public Object get(String key) {
		return mData.get(key);
	}

	public String getString(String key) {
		return String.valueOf(mData.get(key));
	}
}
