package com.assimilate.alltrans.common

import android.content.Context
import android.content.SharedPreferences
import com.assimilate.alltrans.MyApp

class AppStore(context: Context) {
    private val sharedPreferences: SharedPreferences =
        context.getSharedPreferences("AppStore", Context.MODE_PRIVATE)

    val showAdIntervalTime: Long
        get() = sharedPreferences.getLong("showAdIntervalTime", DEFAULT_INTERVAL_TIME)

    val adMessage: String
        get() = sharedPreferences.getString(MyApp.Config.adKey, DEFAULT_WELCOME_MESSAGE) ?: DEFAULT_WELCOME_MESSAGE

    fun saveLong(key: String, value: Long) {
        sharedPreferences.edit().putLong(key, value).apply()
    }

    fun saveString(key: String, value: String) {
        sharedPreferences.edit().putString(key, value).apply()
    }

    companion object {
        private const val DEFAULT_INTERVAL_TIME: Long = 3000 // 默认间隔时间，单位毫秒
        private const val DEFAULT_WELCOME_MESSAGE: String = "" // 默认欢迎信息
    }
}