package com.adealink.weparty.module.profile

import androidx.lifecycle.ViewModelStoreOwner
import com.adealink.frame.aab.BaseDynamicModule
import com.adealink.frame.base.IError
import com.adealink.frame.base.Rlt
import com.adealink.weparty.R
import com.adealink.weparty.module.profile.data.UserConfigType
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.module.profile.viewmodel.IFollowViewModel
import com.adealink.weparty.module.profile.viewmodel.IProfileViewModel

object ProfileModule : BaseDynamicModule<IProfileService>(IProfileService::class), IProfileService {

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

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

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

            override fun getMyUid(): String {
                return ""
            }

            override fun getMyUserInfo(): UserInfo? {
                return null
            }

            override fun setMyUserInfo(userInfo: UserInfo) {
            }

            override fun updateMyUserCountryInfo(
                country: String,
                region: String,
                countryFlag: String
            ) {
            }

            override fun getCacheUserInfo(uid: String): UserInfo? {
                return null
            }

            override fun updateCacheUserInfo(userInfo: UserInfo) {

            }

            override suspend fun getUserInfoByUid(
                uid: String,
                cache: Boolean,
                attrSet: Set<UserConfigType>?,
            ): Rlt<UserInfo> {
                return Rlt.Failed(IError())
            }

            override suspend fun getUsersInfoByUid(
                uidSet: Set<String>,
                cache: Boolean,
                attrSet: Set<UserConfigType>?,
            ): Rlt<Map<String, UserInfo>> {
                return Rlt.Failed(IError())
            }

            override fun getProfileViewModel(owner: ViewModelStoreOwner): IProfileViewModel? {
                return null
            }

            override fun getFollowViewModel(owner: ViewModelStoreOwner): IFollowViewModel? {
                return null
            }

            override fun logout() {

            }

            override fun getService(): IProfileService? {
                return null
            }
        }
    }

    override fun getMyUid(): String {
        return getService().getMyUid()
    }

    override fun getMyUserInfo(): UserInfo? {
        return getService().getMyUserInfo()
    }

    override fun setMyUserInfo(userInfo: UserInfo) {
        getService().setMyUserInfo(userInfo)
    }

    override fun updateMyUserCountryInfo(country: String, region: String, countryFlag: String) {
        getService().updateMyUserCountryInfo(country, region, countryFlag)
    }

    override fun getCacheUserInfo(uid: String): UserInfo? {
        return getService().getCacheUserInfo(uid)
    }

    override suspend fun getUserInfoByUid(
        uid: String,
        cache: Boolean,
        attrSet: Set<UserConfigType>?,
    ): Rlt<UserInfo> {
        return getService().getUserInfoByUid(uid, cache, attrSet)
    }

    override suspend fun getUsersInfoByUid(
        uidSet: Set<String>,
        cache: Boolean,
        attrSet: Set<UserConfigType>?,
    ): Rlt<Map<String, UserInfo>> {
        return getService().getUsersInfoByUid(uidSet, cache, attrSet)
    }

    override fun getProfileViewModel(owner: ViewModelStoreOwner): IProfileViewModel? {
        return getService().getProfileViewModel(owner)
    }

    override fun getFollowViewModel(owner: ViewModelStoreOwner): IFollowViewModel? {
        return getService().getFollowViewModel(owner)
    }

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

    override fun updateCacheUserInfo(userInfo: UserInfo) {
        getService().updateCacheUserInfo(userInfo)
    }
}