package com.iscs.bozzys.event

import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow

/**
 * 授权事件总线
 */
object AuthEventBus {

    private val _events = MutableSharedFlow<AuthEvent>(extraBufferCapacity = 1)

    val events = _events.asSharedFlow()

    fun onTokenExpired() {
        _events.tryEmit(AuthEvent.TokenExpired)
    }
}

/**
 * 授权事件封装
 */
sealed class AuthEvent {
    object TokenExpired : AuthEvent()
}

/**
 * 刷新事件总线
 */
object RefreshEventBus {
    private val _events = MutableSharedFlow<RefreshEvent>(extraBufferCapacity = 1)

    val events = _events.asSharedFlow()

    fun onRefreshData(event: RefreshEvent) {
        _events.tryEmit(event)
    }
}

sealed class RefreshEvent(var value: Any = Any()) {
    // 刷新首页数据 Home/Jobs/Tasks
    object HomeData : RefreshEvent()

    // 更新地图位置到顶部居中
    object UpdateNodeToMapTopCenter : RefreshEvent()

    // 刷新Job详情数据
    object JobDetail : RefreshEvent()

    // 通知事件
    object Notification : RefreshEvent()

    // 通知更新用户信息
    object UpdateUserInfo : RefreshEvent()
}