package com.adealink.weparty.room.data

import com.adealink.frame.data.json.froJsonErrorNull
import com.adealink.frame.util.safeToInt
import com.adealink.weparty.module.room.data.RoomType
import io.trtc.tuikit.atomicxcore.api.live.LiveInfo

//主持人列表（数组）
const val ROOM_META_HOST_LIST = "moderators"

fun LiveInfo.hostList(): List<String> {
    val adminListStr = metaData[ROOM_META_HOST_LIST]
    if (adminListStr.isNullOrEmpty()) {
        return emptyList()
    }
    return froJsonErrorNull<List<String>>(adminListStr) ?: emptyList()
}


//连麦申请人数
const val ROOM_META_MIC_APPLY_NUMBER = "mic_apply_num"

fun LiveInfo.applyMicMemberCount(): Int {
    return metaData[ROOM_META_MIC_APPLY_NUMBER]?.safeToInt(0) ?: 0
}


//默认上麦关闭音频流(0=false,1=true)
const val ROOM_META_AUTO_MIC_MUTE = "state_mic_mute"

fun LiveInfo.isAutoMuteMic(): Boolean {
    return metaData[ROOM_META_AUTO_MIC_MUTE] == "1"
}

//房间类型
const val ROOM_META_ROOM_TYPE = "state_room_type"

fun LiveInfo.roomType(): RoomType? {
    val roomTypeInt = metaData[ROOM_META_ROOM_TYPE]?.safeToInt(-1)
    return RoomType.map(roomTypeInt)
}

fun LiveInfo.isSupportRoomType(): Boolean {
    val roomTypeStr = metaData[ROOM_META_ROOM_TYPE]
    if (roomTypeStr.isNullOrEmpty()) {
        return true
    }
    return RoomType.isSupportRoomType(roomTypeStr.safeToInt(-1))
}