package com.adealink.weparty.room.sdk.controller

import com.adealink.frame.base.IError
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.room.sdk.listener.ISeatListener
import io.trtc.tuikit.atomicxcore.api.live.SeatInfo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.StateFlow

interface ISeatController<L : ISeatListener> : IController<L> {

    var selfMicSeatInfo: StateFlow<SeatInfo?>

    val micSeatsFlow: StateFlow<Map<Int, SeatInfo>>

    val speakingUsersFlow: StateFlow<Map<String, Boolean>>

    fun getMySeatInfo(): SeatInfo?

    fun getMyMicIndex(): Int?

    fun handleMicSeatsInfo(
        roomId: String,
        micSeatsInfo: List<SeatInfo>,
        micUserInfo: Map<Long, UserInfo>? = null,
    )

    fun isOnMic(uid: String): Boolean

    fun getMicSeatIndex(uid: String): Int?

    fun micOn(micInex: Int,onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun micOff(onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun kick(uid: String, onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun micLock(micInex: Int, onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun micUnLock(micInex: Int, onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun micMute(uid: String, onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    fun micUnMute(uid: String, onSuccess: (() -> Unit)? = null, onFail: ((error: IError) -> Unit)? = null)

    suspend fun getMicSeatsInfo()

    fun observeMicSeatsInfo(
        scope: CoroutineScope,
        action: (
            roomId: String,
            micSeatsInfo: List<SeatInfo>
        ) -> Unit
    ): Job

}