package com.zaojiao.app.core.auth.utils

import com.zaojiao.app.core.auth.model.TokenModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import java.util.concurrent.CompletableFuture

enum class AuthState { IN, OUT }

object AuthUtils {
    private var request: ITokenRequest? = null

    internal var _state: AuthState = AuthState.OUT
    val state: AuthState get() = _state

    fun attach(request: ITokenRequest) {
        this.request = request
    }

    fun detach() {
        request = null
    }

    @Deprecated("don't use")
    fun navToLogin(): CompletableFuture<TokenModel?> {
        assert(request != null) { "AuthUtils must called attach in MainActivity" }
        return request!!.requestToken()
    }

    fun requestLogin() {
        assert(request != null) { "AuthUtils must called attach in MainActivity" }
        request!!.requestLogin()
    }
}