package com.rosetta.messenger.network

import com.rosetta.messenger.network.connection.DeviceRuntimeService
import com.rosetta.messenger.network.connection.OwnProfileSyncService
import com.rosetta.messenger.network.connection.PacketRouter
import com.rosetta.messenger.network.connection.PresenceTypingService

class RuntimeDirectoryFacade(
    private val packetRouter: PacketRouter,
    private val ownProfileSyncService: OwnProfileSyncService,
    private val deviceRuntimeService: DeviceRuntimeService,
    private val presenceTypingService: PresenceTypingService
) {
    fun getTypingUsersForDialog(dialogKey: String): Set<String> {
        return presenceTypingService.getTypingUsersForDialog(dialogKey)
    }

    suspend fun resolveUserName(publicKey: String, timeoutMs: Long = 3000): String? {
        return packetRouter.resolveUserName(publicKey = publicKey, timeoutMs = timeoutMs)
    }

    fun getCachedUserName(publicKey: String): String? {
        return packetRouter.getCachedUserName(publicKey)
    }

    fun notifyOwnProfileUpdated() {
        ownProfileSyncService.notifyOwnProfileUpdated()
    }

    fun getCachedUserInfo(publicKey: String): SearchUser? {
        return packetRouter.getCachedUserInfo(publicKey)
    }

    fun getCachedUserByUsername(username: String): SearchUser? {
        return packetRouter.getCachedUserByUsername(username)
    }

    suspend fun resolveUserInfo(publicKey: String, timeoutMs: Long = 3000): SearchUser? {
        return packetRouter.resolveUserInfo(publicKey = publicKey, timeoutMs = timeoutMs)
    }

    suspend fun searchUsers(query: String, timeoutMs: Long = 3000): List<SearchUser> {
        return packetRouter.searchUsers(query = query, timeoutMs = timeoutMs)
    }

    fun acceptDevice(deviceId: String) {
        deviceRuntimeService.acceptDevice(deviceId)
    }

    fun declineDevice(deviceId: String) {
        deviceRuntimeService.declineDevice(deviceId)
    }
}
