package com.example.myapplication.network

import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow

object AuthEventBus {

    // replay=0：不缓存历史事件；extraBufferCapacity：避免瞬时丢事件
    private val _events = MutableSharedFlow<AuthEvent>(
        replay = 0,
        extraBufferCapacity = 1
    )

    val events: SharedFlow<AuthEvent> = _events

    fun emit(event: AuthEvent) {
        _events.tryEmit(event)
    }
}

sealed class AuthEvent {
    data class TokenExpired(val message: String? = null) : AuthEvent()
    data class GenericError(val message: String) : AuthEvent()
}
