package cn.yyxx.commsdk.core.network;

import static cn.yyxx.commsdk.core.network.Hosts.HOST;

import android.content.Context;

import org.json.JSONException;
import org.json.JSONObject;

import cn.yyxx.commsdk.base.internal.ICallback;
import cn.yyxx.commsdk.base.internal.IRequestCallback;

import cn.yyxx.commsdk.core.SdkDrive;
import cn.yyxx.commsdk.core.common.CommonOperationManager;
import cn.yyxx.commsdk.core.utils.ManifestUtils;
import cn.yyxx.support.PropertiesUtils;

public class SdkRequest {
    private static volatile SdkRequest mInstance;

    private SdkRequest(){}
    public static SdkRequest getInstance(){
        if (mInstance == null){
            synchronized (SdkRequest.class){
                mInstance = new SdkRequest();
            }
        }
        return mInstance;
    }

    public void initAgreement(Context context, IRequestCallback callback){
        String game_code = PropertiesUtils.getValue4Properties(context,"yyxx_cfg.properties","yyxx_game","YYXX_GAME_CODE");
        String gcp_code = ManifestUtils.getMetaDataValue(context,"gcp_code");
        JSONObject json = new JSONObject();
        try {
            json.put("game_code",game_code);
            json.put("gcp_code",gcp_code);
            json.put("route_path", Hosts.BASIC_URL_INIT_AGREEMENT);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        String paramText = SdkDrive.getInstance().invokeJobWithoutParams(json.toString());
        VolleyRequest.post(context,HOST,paramText,callback);
    }
    public void  initSdk(Context context, IRequestCallback callback){

        String ifa = CommonOperationManager.getInstance().getIfa(context);
        String ifa_type = "1";


        JSONObject json = new JSONObject();
        try {
            json.put("ifa",ifa);
            json.put("ifa_type",ifa_type);
            json.put("route_path",Hosts.BASIC_URL_INIT_SDK);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String paramText = SdkDrive.getInstance().invokeJob(json.toString());
        VolleyRequest.post(context,HOST,paramText,callback);
    }
}
