package com.sambath.sbc.util

import android.content.Context
import android.content.SharedPreferences
import com.sambath.sbc.util.Const.Companion.AUTO_PRINT_KEY
import com.sambath.sbc.util.Const.Companion.CHANNEL_TYPE
import com.sambath.sbc.util.Const.Companion.MAX_KEY
import com.sambath.sbc.util.Const.Companion.MIN_KEY
import com.sambath.sbc.util.Const.Companion.MUTE_KEY
import com.sambath.sbc.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, "Bearer $token").apply()

    fun setChannelType(channelType: Int) = sharedPreferences.edit().putInt(CHANNEL_TYPE, channelType).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 getChannelType() = sharedPreferences.getInt(CHANNEL_TYPE, 1) ?: 1

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