package com.adealink.weparty.module.room

import com.adealink.frame.aab.BaseDynamicModule
import com.adealink.frame.aab.constant.AABModuleNotInitError
import com.adealink.frame.base.Rlt
import com.adealink.frame.media.IMediaOperator
import com.adealink.frame.media.MediaConflictConfig
import com.adealink.frame.media.MediaInfo
import com.adealink.weparty.R
import com.adealink.weparty.commonui.BaseActivity
import com.adealink.weparty.commonui.widget.floatview.data.IFloatData
import com.adealink.weparty.commonui.widget.floatview.view.BaseFloatView

object RoomModule : BaseDynamicModule<IRoomService>(IRoomService::class), IRoomService {

    override val featureName: String
        get() = "room"

    override val moduleNameResId: Int
        get() = R.string.module_room

    override fun emptyService(): IRoomService {
        return object : IRoomService {
            override fun getService(): IRoomService? {
                return null
            }

            override fun getMediaOperator(): IMediaOperator {
                return object : IMediaOperator {
                    override suspend fun confirmExitConflictMedia(
                        exitMediaInfo: MediaInfo,
                        enterMediaInfo: MediaInfo
                    ): Rlt<Any> {
                        return Rlt.Failed(AABModuleNotInitError())
                    }

                    override fun getConflictConfig(): MediaConflictConfig {
                        return MediaConflictConfig(
                            MediaInfo(
                                com.adealink.weparty.media.MediaType.UNKNOWN.type,
                                ""
                            ), false
                        )
                    }

                    override fun getJoinedRoomId(): String? {
                        return null
                    }

                    override suspend fun isMediaIn(): Boolean {
                        return false
                    }

                    override suspend fun leaveMedia(): Rlt<Any> {
                        return Rlt.Failed(AABModuleNotInitError())
                    }

                    override suspend fun rejoinRoom(): Rlt<Any> {
                        return Rlt.Failed(AABModuleNotInitError())
                    }

                }
            }

            override fun init() {
            }

            override fun checkRoomPermission() {
            }

            override fun createRoom(activity: BaseActivity) {
            }

            override fun getMinimizedRoomView(data: IFloatData): BaseFloatView<out IFloatData>? {
                return null
            }

            override fun getJoinedRoomId(): String? {
                return null
            }

            override fun isInRoom(): Boolean {
                return false
            }

            override fun onLogout() {
            }

        }
    }

    override fun getMediaOperator(): IMediaOperator {
        return getService().getMediaOperator()
    }

    override fun init() {
        getService().init()
    }

    override fun checkRoomPermission() {
        getService().checkRoomPermission()
    }

    override fun createRoom(activity: BaseActivity) {
        getService().createRoom(activity)
    }

    override fun getMinimizedRoomView(data: IFloatData): BaseFloatView<out IFloatData>? {
        return getService().getMinimizedRoomView(data)
    }

    override fun getJoinedRoomId(): String? {
        return getService().getJoinedRoomId()
    }

    override fun isInRoom(): Boolean {
        return getService().isInRoom()
    }

    override fun onLogout() {
        getService().onLogout()
    }

}