package com.swago.room.audio

import com.swago.baseswago.model.live.audio.AudioSeatModel
import com.swago.baseswago.model.live.audio.IMAudioModel
import io.agora.rtc.IRtcEngineEventHandler

object AudioRoomManager {

    //两个字段用户端使用
    var isOnMic = false
    var maiIndex = -1

    private val list = ArrayList<IAudioRoomListener>()

    fun addListener(iAudioRoomListener: IAudioRoomListener){
        list.add(iAudioRoomListener)
    }

    fun removeListener(iAudioRoomListener: IAudioRoomListener){
        list.remove(iAudioRoomListener)
    }

    /**
     * 锁和解锁麦位
     */
    fun dispatchLockOrUnlockSeat(imAudioModel: IMAudioModel){
        list.forEach {
            it.lockOrUnlockSeat(imAudioModel)
        }
    }

    /**
     * 开麦和闭麦
     */
    fun dispatchOpenSeatMic(){
        list.forEach {
            it.openSeatMic()
        }
    }

    fun dispatchMuteSeatMic(){
        list.forEach {
            it.muteSeatMic()
        }
    }

    /**
     * 上麦和下麦
     */
    fun dispatchOnSeatMic(){
        list.forEach {
            it.onSeatMic()
        }
    }

    fun dispatchDownSeatMic(){
        list.forEach {
            it.downSeatMic()
        }
    }

    /**
     * 改变积分
     */
    fun dispatchChangeJiFen(imAudioModel: IMAudioModel){
        list.forEach {
            it.changeJiFen(imAudioModel)
        }
    }

    fun dispatchUpdateData(audioSeatModel: AudioSeatModel){
        list.forEach {
            it.updateData(audioSeatModel)
        }
    }

    /**
     * 积分清零
     */
    fun dispatchClearJiFen(){
        list.forEach {
            it.clearJiFen()
        }
    }

    /**
     * 用户说话回调
     */
    fun dispatchOnAudioVolumeIndication(speakers: Array<out IRtcEngineEventHandler.AudioVolumeInfo>?){
        list.forEach {
            it.onAudioVolumeIndication(speakers)
        }
    }


    fun resetData(){
        isOnMic = false
        maiIndex = -1
    }

}