package com.adealink.weparty.module.account

import androidx.fragment.app.FragmentManager
import com.adealink.frame.aab.BaseDynamicModule
import com.adealink.weparty.R
import com.adealink.weparty.module.account.data.UserKickReason

object AccountModule : BaseDynamicModule<IAccountService>(IAccountService::class), IAccountService {

    override val featureName: String
        get() = "account"

    override val moduleNameResId: Int
        get() = R.string.module_account

    override val uid: String
        get() = getService().uid

    override val token: String
        get() = getService().token

    override fun showLoginDialog(fm: FragmentManager?) {
        getService().showLoginDialog(fm)
    }

    override fun logout(toLogin: Boolean?) {
        performDownload()
        getService().logout(toLogin)
    }

    override fun onKickedOffline(reason: UserKickReason) {
        performDownload()
        getService().onKickedOffline(reason)
    }

    override fun isLogin(): Boolean {
        return getService().isLogin()
    }

    override fun registerListener(l: ILoginListener) {
        getService().registerListener(l)
    }

    override fun unregisterListener(l: ILoginListener) {
        getService().unregisterListener(l)
    }

    override fun checkRemoteVirtualAppConfig() {
        getService().checkRemoteVirtualAppConfig()
    }

    override fun onTokenExpire() {
        performDownload()
        getService().onTokenExpire()
    }

    override fun emptyService(): IAccountService {
        return object : IAccountService {

            override fun getService(): IAccountService? {
                return null
            }

            override val uid: String
                get() = ""

            override val token: String
                get() = ""

            override fun showLoginDialog(fm: FragmentManager?) {
            }

            override fun logout(toLogin: Boolean?) {

            }

            override fun onKickedOffline(reason: UserKickReason) {
            }

            override fun isLogin(): Boolean {
                return false
            }

            override fun registerListener(l: ILoginListener) {

            }

            override fun unregisterListener(l: ILoginListener) {

            }

            override fun refreshToken() {

            }

            override fun checkRemoteVirtualAppConfig() {

            }

            override fun onTokenExpire() {

            }

            override fun onLogout() {
            }

        }
    }

    override fun refreshToken() {
        getService().refreshToken()
    }

    override fun onLogout() {
        getService().onLogout()
    }
}