package com.yyrh.factory;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;

import com.yyrh.constant.RoleInfo;
import com.yyrh.constant.SDKSettings;
import com.yyrh.core.internal.IImplCallback;
import com.yyrh.sdk.SDKEntry;
import com.yyrh.sdk.YyrhSdkManager;
import com.yyrh.sdk.callback.InitCallback;
import com.yyrh.sdk.callback.LogoutCallback;
import com.yyrh.sdk.callback.RealNameMsgCallback;
import com.yyrh.utils.Utils;
import com.yyrh.utils.YYLog;
import com.yythird.base.ChannelSdkCallback;
import com.yythird.sdk.ChannelSDK;

import org.json.JSONObject;

import java.util.HashMap;


public class ChannelSdkOperation implements ISdkOperation {
    private static ChannelSDK channelSdk = null;

    public ChannelSdkOperation() {
        channelSdk = ChannelSDK.getInstance();
    }

    @Override
    public void login(Activity activity) {
        channelSdk.SDKLogin(activity, SDKEntry.getSdkInstance().sdkCallback);
    }

    @Override
    public void uploadRoleInfo(String type, Activity activity, RoleInfo roleInfo) {
        String roleId = roleInfo.getRoleId();
        String roleName = roleInfo.getRoleName();
        String roleLevel = roleInfo.getRoleLevel();
        String gender = roleInfo.getGender();
        String serverId = roleInfo.getServerId();
        String serverName = roleInfo.getServerName();
        String hasGold = roleInfo.getHasGold();
        String vipLevel = roleInfo.getVipLevel();
        String roleCreateTime = roleInfo.getRoleCreateTime();
        String partyName = roleInfo.getPartyName();
        String role_power = roleInfo.getRolePower();
        String partyId = roleInfo.getPartyId();
        String reincarnationCount = roleInfo.getReincarnationCount();


        if (Utils.judgeStrNull(roleId) || Utils.judgeStrNull(roleName)
                || Utils.judgeStrNull(roleLevel)
                || Utils.judgeStrNull(gender)
                || Utils.judgeStrNull(serverId)
                || Utils.judgeStrNull(serverName)
                || Utils.judgeStrNull(hasGold)
                || Utils.judgeStrNull(vipLevel)
                || Utils.judgeStrNull(roleCreateTime)
                || Utils.judgeStrNull(role_power)
                || Utils.judgeStrNull(partyId)
                || Utils.judgeStrNull(reincarnationCount)) {

            YYLog.i("上传参数有空值，请检查: " + roleInfo.getAllParam());

        } else {

            channelSdk.SDKUploadInfo(type, activity, roleInfo);

        }
    }

    @Override
    public void setSDKLogoutListener(Activity activity, ChannelSdkCallback sdkCallback) {
        channelSdk.setSDKLogoutListener(activity, sdkCallback);
    }

    @Override
    public void pay(Activity activity, HashMap<String, Object> map) {

        if (SDKSettings.isThirdPay) {
            channelSdk.SDKPay(activity, map, SdkManager.defaultManager().sdkCallback);
        } else {
            YyrhSdkManager.defaultManager().yyrhPay(activity, map);
        }

    }

    @Override
    public void exit(Activity activity) {
        channelSdk.SDKExit(activity, SDKEntry.getSdkInstance().sdkCallback);
    }

    @Override
    public void logOut() {
        channelSdk.SDKLogout();
    }

    @Override
    public void getRealNameInfo(Activity activity, RealNameMsgCallback realNameMsgCallback) {
        if (Utils.getTextIsNull(SDKSettings.loginData.rn_bd)) {
            ChannelSDK.getInstance().onGetChannelRealNameInfo(activity);
        } else {
            realNameMsgCallback.onLoadRealNameMsg(true, SDKSettings.loginData.rn_bd);
        }
    }

    @Override
    public void reportAdEvent(String event, JSONObject json) {
        channelSdk.SDKReportAdInfo(event, json);
    }

    @Override
    public void sdkOnStart(Activity activity) {
        channelSdk.onStart(activity);
    }

    @Override
    public void sdkOnCreate(Activity activity, Bundle savedInstanceState) {
        channelSdk.onCreate(activity, savedInstanceState);
    }

    @Override
    public void sdkOnPause(Activity activity) {
        channelSdk.onPause(activity);
    }

    @Override
    public void sdkOnResume(Activity activity) {
        channelSdk.onResume(activity);
    }

    @Override
    public void sdkOnRestart(Activity activity) {
        channelSdk.onRestart(activity);
    }

    @Override
    public void sdkOnNewIntent(Activity acitivty, Intent intent) {
        channelSdk.onNewIntent(acitivty, intent);
    }

    @Override
    public void sdkOnStop(Activity activity) {
        channelSdk.onStop(activity);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfigs) {
        channelSdk.onConfigurationChanged(newConfigs);
    }

    @Override
    public void sdkOnDestroy(Activity activity) {
        channelSdk.onDestroy(activity);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        channelSdk.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void onActivityResult(Activity ac, int requestCode, int resultCode, Intent data) {
        channelSdk.onActivityResult(ac, requestCode, resultCode, data);
    }

    @Override
    public void onWindowFocusChanged(Activity activity, boolean hasFocus) {
        channelSdk.onWindowFocusChanged(activity, hasFocus);
    }
}
