package com.devlab.app.data.api

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

object SessionManager {

    private val _isSessionValid = MutableStateFlow(true)
    val isSessionValid: StateFlow<Boolean> = _isSessionValid.asStateFlow()

    private val _onLogoutRequest = MutableStateFlow(false)
    val onLogoutRequest: StateFlow<Boolean> = _onLogoutRequest.asStateFlow()

    fun invalidateSession() {
        _isSessionValid.value = false
        _onLogoutRequest.value = true
        RetrofitClient.setToken("")
    }

    fun restoreSession() {
        _isSessionValid.value = true
        _onLogoutRequest.value = false
    }

    fun consumeLogoutRequest() {
        _onLogoutRequest.value = false
    }
}
