package com.adealink.weparty.module.call

import android.app.Application
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.widget.floatview.data.IFloatData
import com.adealink.weparty.commonui.widget.floatview.view.BaseFloatView

object CallModule : BaseDynamicModule<ICallService>(ICallService::class), ICallService {

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

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

    override fun emptyService(): ICallService {
        return object : ICallService {

            override fun call(
                uid: String,
                onSuccess: (() -> Unit)?,
                onFail: ((errCode: Int, errMsg: String?) -> Unit)?
            ) {
            }

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

            override fun getService(): ICallService? {
                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 appOnCreateMainTask(application: Application) {
            }

            override fun appOnCreateSubTask(application: Application) {
            }

            override fun activityOnCreateMainTask() {
            }

            override fun activityOnCreateSubTask() {
            }

            override fun onLogout() {
            }

        }
    }

    override fun call(
        uid: String,
        onSuccess: (() -> Unit)?,
        onFail: ((Int, String?) -> Unit)?
    ) {
        getService().call(uid, onSuccess, onFail)
    }

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

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

    override fun appOnCreateMainTask(application: Application) {
        return getService().appOnCreateMainTask(application)
    }

    override fun appOnCreateSubTask(application: Application) {
        return getService().appOnCreateSubTask(application)
    }

    override fun activityOnCreateMainTask() {
        return getService().activityOnCreateMainTask()
    }

    override fun activityOnCreateSubTask() {
        return getService().activityOnCreateSubTask()
    }

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

}