package com.adealink.weparty.module.room.data

import io.trtc.tuikit.atomicxcore.api.live.SeatInfo


/**
 * 麦位操作
 */
enum class MicOperate(val op: Long) {
    MIC_ON(0), //上麦
    MIC_OFF(1), //下麦
    MIC_LOCK(2), //封禁麦位
    MIC_UN_LOCK(3), //解除麦位封禁
    MIC_MUTE(4), //麦位静音
    MIC_UN_MUTE(5), //解除麦位静音
    MIC_INVITE_OLD(6), //麦位邀请(废弃)
    MIC_LISTEN(7), //设置旁听（踢麦）
    MIC_INVITE(8), //麦位邀请
    MIC_ACCEPT_INVITE(9), //接受邀请
    MIC_REJECT_INVITE(10), //拒绝邀请
}


/**
 * 麦位状态
 */
enum class MicSeatStatus(val status: Int) {
    NORMAL(0), //正常状态
    MUTE(1), //静音
    LOCK(2) //封禁
}

fun SeatInfo.micUid(): String? {
    return userInfo.userID
}

fun SeatInfo.isSeatEmpty(): Boolean {
    return userInfo == null || userInfo.userID.isNullOrEmpty()
}

fun SeatInfo.isRemoteMute(): Boolean {
    return !userInfo.allowOpenMicrophone
}

fun SeatInfo.micStatus(): MicSeatStatus {
    if (isLocked) {
        return MicSeatStatus.LOCK
    }
    if (!userInfo.allowOpenMicrophone) {
        return MicSeatStatus.MUTE
    }
    return MicSeatStatus.NORMAL
}

fun List<SeatInfo>.isMicOn(uid: String): Boolean {
    return find { it.micUid() == uid } != null
}