package com.adealink.weparty.room.constant

import android.os.SystemClock
import com.adealink.frame.base.AppBase
import com.adealink.frame.log.Log
import com.adealink.frame.room.data.TAG_ROOM
import com.adealink.weparty.commonui.toast.util.showToast

const val TAG_ROOM_CREATE = "${TAG_ROOM}_create"
const val TAG_ROOM_ENTER_ROOM = "${TAG_ROOM}_enter_room"
const val TAG_ROOM_THEME = "${TAG_ROOM}_theme"

const val TAG_ROOM_CHAT = "${TAG_ROOM}_chat"

const val TAG_ROOM_TIME = "tag_room_time"

var enterRoomTime: Long = 0

var enterRoomJoinReqTime: Long = 0 //发起进房请求的时间
var enterRoomJoinResTime: Long = 0

var enterRoomUILoadTime: Long = 0 //房间UI加载时间(路由时间 -> RoomActivity.onCreate)

fun logRoomTime(msg: String) {
    Log.d(TAG_ROOM_TIME, "$msg, time: ${SystemClock.elapsedRealtime() - enterRoomTime}")
}

fun markEnterRoomTime(time: Long) {
    enterRoomTime = time
    enterRoomJoinReqTime = 0
    enterRoomJoinResTime = 0
    enterRoomUILoadTime = 0
}

fun toastEnterRoomTime() {
    if (AppBase.isRelease) {
        return
    }
    val nowTs = SystemClock.elapsedRealtime()
    val toastContent = StringBuilder()
    toastContent.append("进房总耗时:").append(nowTs - enterRoomTime).append("\n")

    val netTime = enterRoomJoinResTime - enterRoomJoinReqTime
    if (netTime > 0) {
        toastContent.append("网络耗时:").append(netTime).append("\n")
    }

    toastContent.append("UI加载时间:").append(nowTs - enterRoomUILoadTime)

    showToast(toastContent)
}