package melody.offline.music.sp

import android.content.Context
import melody.offline.music.firebase.Constants
import melody.offline.music.sp.store.Store
import melody.offline.music.sp.store.asStoreProvider
import melody.offline.music.util.PlayMode

class AppStore(context: Context) {
    private val store = Store(
        context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).asStoreProvider()
    )

    var searchHistoryStore: Set<String> by store.stringSet(
        key = SEARCH_HISTORY, defaultValue = emptySet()
    )

    var myVisitorData: String by store.string(
        key = MY_VISITOR_DATA, defaultValue = ""
    )

    var playMusicMode: Int by store.int(
        key = PLAY_MUSIC_MODE, defaultValue = PlayMode.LIST_LOOP.value
    )

    var userID: String by store.string(
        key = APP_USERID, defaultValue = ""
    )

    var appUUID: String by store.string(
        key = APP_UUID, defaultValue = ""
    )

    var ipCountryCode: String by store.string(
        key = IP_COUNTRY_CODE, defaultValue = ""
    )

    var firstOpenIsSucceed: Boolean by store.boolean(
        key = FIRST_OPEN_IS_SUCCEED, defaultValue = false
    )

    var shouldEnterMusicPage: Boolean by store.boolean(
        key = SHOULD_ENTER_MUSIC_PAGE, defaultValue = true
    )

    var shouldEnterMusicPageJson: String by store.string(
        key = Constants.KEY_SHOULD_ENTER_MUSIC_JSON,
        defaultValue = Constants.DEFAULT_SHOULD_ENTER_MUSIC_JSON
    )

    //广告json-firebase配置
    var adJson: String by store.string(
        key = Constants.KEY_AD_JSON, defaultValue = Constants.DEFAULT_AD_JSON
    )

    //展示广告的间隔时间
    var showAdIntervalTime: Long by store.long(
        key = Constants.KEY_SHOW_AD_INTERVAL_TIME,
        defaultValue = Constants.DEFAULT_SHOW_AD_INTERVAL_TIME
    )

    companion object {
        private const val FILE_NAME = "music_oo_app"
        const val SEARCH_HISTORY = "search_history"
        const val MY_VISITOR_DATA = "my_visitor_data"
        const val PLAY_MUSIC_MODE = "play_music_mode"
        const val APP_USERID = "app_userid"
        const val APP_UUID = "app_uuid"
        const val IP_COUNTRY_CODE = "ip_country_code"
        const val FIRST_OPEN_IS_SUCCEED = "first_open_is_succeed"
        const val SHOULD_ENTER_MUSIC_PAGE = "key_should_enter_music_page"

    }
}