package cn.yyxx.eyuangame.core

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import cn.yyxx.eyuangame.base.entity.SdkChargeInfo
import cn.yyxx.eyuangame.base.entity.SdkEvent
import cn.yyxx.eyuangame.base.entity.SdkRoleInfo
import cn.yyxx.eyuangame.base.internal.ICallback
import cn.yyxx.eyuangame.base.internal.IInitialize
import cn.yyxx.eyuangame.core.impl.SdkBridgeImpl

/**
 * @author #Suyghur.
 * Created on 2021/06/09
 */
class SdkBridge constructor(context: Context) {

    private var mImpl: SdkBridgeImpl? = null

    init {
        if (mImpl == null) {
            mImpl = SdkBridgeImpl(context)
        }
    }

    fun attachBaseContext(application: Application, context: Context) {
        mImpl?.attachBaseContext(application, context)

    }

    fun initApplication(application: Application) {
        mImpl?.initApplication(application)
    }

    fun initialize(activity: Activity, isLandscape: Boolean, callback: ICallback, initCallback: IInitialize) {
        mImpl?.initialize(activity, isLandscape, callback, initCallback)
    }

    fun login(activity: Activity, isAutoLogin: Boolean, callback: ICallback) {
        mImpl?.login(activity, isAutoLogin, callback)
    }

    fun logout(activity: Activity, callback: ICallback) {
        mImpl?.logout(activity, callback)
    }

    fun charge(activity: Activity, chargeInfo: SdkChargeInfo, isIab: Boolean, callback: ICallback) {
        mImpl?.charge(activity, chargeInfo, isIab, callback)
    }

    fun roleCreate(activity: Activity, roleInfo: SdkRoleInfo) {
        mImpl?.roleCreate(activity, roleInfo)
    }

    fun roleLauncher(activity: Activity, roleInfo: SdkRoleInfo) {
        mImpl?.roleLauncher(activity, roleInfo)
    }

    fun roleLevelUp(activity: Activity, roleInfo: SdkRoleInfo) {
        mImpl?.roleLevelUp(activity, roleInfo)
    }

    fun openExitView(activity: Activity, callback: ICallback) {
        mImpl?.openExitView(activity, callback)
    }

    fun onStart(activity: Activity) {
        mImpl?.onStart(activity)
    }

    fun onRestart(activity: Activity) {
        mImpl?.onRestart(activity)
    }

    fun onResume(activity: Activity) {
        mImpl?.onResume(activity)
    }

    fun onPause(activity: Activity) {
        mImpl?.onPause(activity)
    }

    fun onStop(activity: Activity) {
        mImpl?.onStop(activity)
    }

    fun onDestroy(activity: Activity) {
        mImpl?.onDestroy(activity)
    }

    fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, intent: Intent) {
        mImpl?.onActivityResult(activity, requestCode, resultCode, intent)
    }

    fun onNewIntent(activity: Activity, intent: Intent) {
        mImpl?.onNewIntent(activity, intent)
    }

    fun getCurrentUserId(): String {
        return if (mImpl == null) {
            ""
        } else {
            mImpl!!.getCurrentUserId()
        }
    }

    fun linkingEvent(context: Context, sdkEvent: SdkEvent) {
        mImpl?.linkingEvent(context, sdkEvent)
    }

}