package kr.co.vividnext.sodalive.settings

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager

class ContentSettingsViewModel : BaseViewModel() {
    private var _isAdultContentVisible = MutableLiveData(
        SharedPreferenceManager.isAdultContentVisible
    )
    val isAdultContentVisible: LiveData<Boolean>
        get() = _isAdultContentVisible

    private var _adultContentPreference = MutableLiveData(
        ContentType.values()[SharedPreferenceManager.contentPreference]
    )
    val adultContentPreference: LiveData<ContentType>
        get() = _adultContentPreference

    var isChangedAdultContentVisible = false

    fun toggleAdultContentVisible() {
        val adultContentVisible = SharedPreferenceManager.isAdultContentVisible
        _isAdultContentVisible.value = !adultContentVisible
        SharedPreferenceManager.isAdultContentVisible = !adultContentVisible
        isChangedAdultContentVisible = true

        if (adultContentVisible) {
            SharedPreferenceManager.contentPreference = ContentType.ALL.ordinal
        }
    }

    fun setAdultContentPreference(adultContentPreference: ContentType) {
        _adultContentPreference.value = adultContentPreference
        SharedPreferenceManager.contentPreference = adultContentPreference.ordinal
        isChangedAdultContentVisible = true
    }
}
