package com.khmer9.cflivemain.util

import android.content.Context
import android.content.SharedPreferences
import com.khmer9.cflivemain.util.Const.Companion.AUTO_PRINT_KEY
import com.khmer9.cflivemain.util.Const.Companion.MAX_KEY
import com.khmer9.cflivemain.util.Const.Companion.MIN_KEY
import com.khmer9.cflivemain.util.Const.Companion.MUTE_KEY
import com.khmer9.cflivemain.util.Const.Companion.TOKEN_KEY


class PrefHelper constructor(val context: Context) {
    private var sharedPreferences: SharedPreferences =
        context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)

    fun setIsMute(value: Boolean) = sharedPreferences.edit().putBoolean(MUTE_KEY, value).apply()
    fun setIsAutoPrint(value: Boolean) = sharedPreferences.edit().putBoolean(AUTO_PRINT_KEY, value).apply()

    fun setUserToken(token: String) = sharedPreferences.edit().putString(TOKEN_KEY, token).apply()

    fun getIsMute() = sharedPreferences.getBoolean(MUTE_KEY, false)
    fun getIsAutoPrint() = sharedPreferences.getBoolean(AUTO_PRINT_KEY, false)

    fun setMinBetting(value: Int) = sharedPreferences.edit().putInt(MIN_KEY, value).apply()
    fun setMaxBetting(value: Int) = sharedPreferences.edit().putInt(MAX_KEY, value).apply()

    fun getMinBetting() =
        sharedPreferences.getInt(MIN_KEY, 0)

    fun getMaxBetting() =
        sharedPreferences.getInt(MAX_KEY, 0)


    fun getToken() =
        sharedPreferences.getString(TOKEN_KEY, "") ?: ""

    fun logout() {
        sharedPreferences.edit().remove(TOKEN_KEY).apply()
    }
}