package com.adealink.weparty.media.datasource

import android.content.Context
import com.adealink.frame.media.MediaInfo
import com.adealink.frame.storage.sp.TypeDelegationPrefs
import com.adealink.frame.util.AppUtil
import com.adealink.weparty.media.MediaType
import com.adealink.weparty.module.profile.ProfileModule
import com.adealink.weparty.storage.PREF_MEDIA

object MediaLocalService : TypeDelegationPrefs(
    prefs = {
        AppUtil.appContext.getSharedPreferences(PREF_MEDIA, Context.MODE_PRIVATE)
    },
    userId = {
        ProfileModule.getMyUid()
    }
) {

    var room2CallConflictRemind: Boolean by PrefUserKey("key_room_2_call_conflict", true)
    var call2RoomConflictRemind: Boolean by PrefUserKey("key_room_2_call_conflict", true)


    fun showConflictRemind(
        exitMediaInfo: MediaInfo?,
        enterMediaInfo: MediaInfo?
    ): Boolean {
        return if (exitMediaInfo?.mediaType == MediaType.CHAT_ROOM.type && enterMediaInfo?.mediaType == MediaType.CALL_1V1.type) {
            room2CallConflictRemind
        } else if (exitMediaInfo?.mediaType == MediaType.CALL_1V1.type && enterMediaInfo?.mediaType == MediaType.CHAT_ROOM.type) {
            call2RoomConflictRemind
        } else {
            false
        }

    }

    fun updateConflictRemind(
        exitMediaInfo: MediaInfo?,
        enterMediaInfo: MediaInfo?,
        neverRemind: Boolean
    ) {
        if (exitMediaInfo?.mediaType == MediaType.CHAT_ROOM.type && enterMediaInfo?.mediaType == MediaType.CALL_1V1.type) {
            room2CallConflictRemind = neverRemind
        } else if (exitMediaInfo?.mediaType == MediaType.CALL_1V1.type && enterMediaInfo?.mediaType == MediaType.CHAT_ROOM.type) {
            call2RoomConflictRemind = neverRemind
        }
    }
}