package com.rosetta.messenger.network.connection

import com.rosetta.messenger.network.Packet
import com.rosetta.messenger.network.PacketSubscriptionRegistry
import kotlinx.coroutines.flow.SharedFlow

class PacketSubscriptionFacade(
    private val packetSubscriptionRegistry: PacketSubscriptionRegistry
) {
    fun waitPacket(packetId: Int, callback: (Packet) -> Unit) {
        packetSubscriptionRegistry.addCallback(packetId, callback)
    }

    fun unwaitPacket(packetId: Int, callback: (Packet) -> Unit) {
        packetSubscriptionRegistry.removeCallback(packetId, callback)
    }

    fun packetFlow(packetId: Int): SharedFlow<Packet> {
        return packetSubscriptionRegistry.flow(packetId)
    }
}
