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

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

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

/**
 * @Description: 渠道封装基类
 * @Author: FLuty
 * @CreateDate: 2020/3/24 15:19
 */
public abstract class FQPluginApi {
    /**
     * 初始化
     * @param activity
     * @param handler
     */
    public abstract void init(Context activity, PluginResultHandler handler);

    /**
     * 登录
     * @param activity
     * @param handler
     */
    public abstract void login(final Context activity, final PluginResultHandler handler);
    /**
     * 支付
     * @param activity
     * @param map
     * @param handler
     */
    public abstract void pay(Context activity, Map<String, Object> map, final PluginResultHandler handler);
    /**
     * 登出
     * @param context
     * @param prh
     */
    public abstract void logout(Context context, PluginResultHandler prh);
    /**
     * 切换用户
     * @param activity
     * @param prh
     */
    public abstract void changeAccount(final Activity activity, final PluginResultHandler prh);
    /**
     * 退出
     * @param context
     * @param cb
     */
    public abstract void exit(Context context, final PluginResultHandler cb);
    /**
     * 游戏角色数据上报
     * @param data
     */
    public abstract void setRoleInfo(Bundle data);

    /**
     * 获取权限结果
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    public void onRequestPermissionsResult(int requestCode,
                                           String[] permissions, int[] grantResults){}


    /** 生命周期相关方法（非业务）*/
    public abstract void onCreate(Context context, Bundle savedInstanceState);
    public abstract void onSaveInstanceState(Context context, Bundle outState);
    public abstract void onRestart(Context context);
    public abstract void onStart(Context context);
    public abstract void onResume(Context context);
    public abstract void onPause(Context context);
    public abstract void onStop(Context context);
    public abstract void onNewIntent(Intent intent);
    public abstract void attachBaseContext(Context context);
    public abstract void onApplicationCreate(Context context);
    public abstract void onActivityResult(int requestCode, int resultCode, Intent data);
    public abstract void onDestroy(Context context);

    /** 通用回调方法（初始化、登录、支付）*/
    public void initFqSdkSuccess(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.OK));
        }
    }

    public void initFqSdkError(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.ERROR));
        }
    }

    public void loginFqSdkSuccess(PluginResultHandler cb, HashMap<String, String> loginAuthData ) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.OK, loginAuthData));
        }
    }

    public void loginFqSdkError(PluginResultHandler cb, String errorMessage) {
        if (cb != null) {

            if(null == errorMessage) {
                cb.onHandlePluginResult(new PluginResult(
                        PluginResult.Status.ERROR));
            } else {
                cb.onHandlePluginResult(new PluginResult(
                        PluginResult.Status.ERROR, errorMessage));
            }


        }
    }

    public void loginFqSdkCancle(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.CANCEL));
        }
    }

    public void payFqSdkSuccess(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.OK));
        }
    }

    public void payFqSdkError(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.CANCEL));
        }
    }

    public void payFqSdkCancel(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.CANCEL));
        }
    }

    public void exitFqSdkNoConfirmDialog(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(PluginResult.Status.CANCEL));
        }
    }

    public void exitFqSdk(PluginResultHandler cb) {
        if (cb != null) {
            cb.onHandlePluginResult(new PluginResult(
                    PluginResult.Status.OK));
        }
    }


}
