package com.yyrh.core.network;

import android.content.Context;

import com.yyrh.core.SDKDrive;
import com.yyrh.core.internal.IRequestCallback;

import org.json.JSONObject;

/**
 * @author #Suyghur.
 * Created on 2021/10/15
 */
public final class SdkRequest {

    private SdkRequest() {

    }

    public static void initSdk(Context context, IRequestCallback callback) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("route_path", Host.BASIC_ROUTE_INIT_SDK);
        } catch (Exception e) {
            e.printStackTrace();
        }
        VolleyRequest.post(context, jsonObject, callback);
    }

    public static void accountRegister(Context context, String userName, String pwd, IRequestCallback callback) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("uname_pwd", SDKDrive.getInstance().RsaEncrypt(userName + "|" + pwd));
            jsonObject.put("route_path", Host.BASIC_ROUTE_FAST_REGISTER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        VolleyRequest.post(context, jsonObject, callback);
    }

    public static void accountLauncher(Context context, String userName, String pwd, IRequestCallback callback) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("uname_pwd", SDKDrive.getInstance().RsaEncrypt(userName + "|" + pwd));
            jsonObject.put("route_path", Host.BASIC_ROUTE_USER_LOGIN);
        } catch (Exception e) {
            e.printStackTrace();
        }
        VolleyRequest.post(context, jsonObject, callback);
    }

    public static void phoneRegister(Context context, String phone, String pwd, String captcha, IRequestCallback callback) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("uname_pwd", SDKDrive.getInstance().RsaEncrypt(phone + "|" + pwd));
            jsonObject.put("sms", captcha);
            jsonObject.put("route_path", Host.BASIC_ROUTE_PHONE_REGISTER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        VolleyRequest.post(context, jsonObject, callback);
    }

    public static void getCaptcha(Context context, String action, String phone, IRequestCallback callback) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("action", action);
            jsonObject.put("phone", phone);
            jsonObject.put("route_path", Host.BASIC_ROUTE_PHONE_CAPTCHA);
        } catch (Exception e) {
            e.printStackTrace();
        }
        VolleyRequest.post(context, jsonObject, callback);
    }
}
