package com.gh.gamecenter.login.provider

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IUserManagerProvider
import com.gh.gamecenter.login.user.UserManager

@Route(path = RouteConsts.provider.userManager, name = "UserManager暴露服务")
class UserManagerProviderImpl : IUserManagerProvider {
    override fun userShouldTakeRegulationBaseOnLastRemind(): Boolean {
        return UserManager.getInstance().userShouldTakeRegulationBaseOnLastRemind()
    }

    override fun getUserId(): String {
        return UserManager.getInstance().userId ?: ""
    }

    override fun getToken(): String {
        return UserManager.getInstance().token ?: ""
    }

    override fun refreshToken(accessToken: String, success: () -> Unit, fail: (String?) -> Unit) {
        UserManager.getInstance().refreshToken(accessToken, object : UserManager.refreshCallBack {
            override fun onLogin() {
                success.invoke()
            }

            override fun onLoginFailure(errorMessage: String?) {
                fail.invoke(errorMessage)
            }
        })
    }

    override fun init(context: Context?) {
        // Do nothing
    }
}