package com.guadou.lib_baselib.engine

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import com.guadou.lib_baselib.utils.DataStoreUtils


/**
 * SharedPreferences实现引擎类
 * 内部使用DataStore工具类替换实现
 *
 * sp().getString("a", "default")
 * sp().getBoolean("b", false)
 *
   sp().putString("abc","test demo")

 * sp().clearAll()
}
 */

fun Any.SP(): DataStore<Preferences> {
    return DataStoreUtils.dataStore
}

fun DataStore<Preferences>.putString(key: String, value: String) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getString(key: String, default: String = ""): String {
    return DataStoreUtils.getData(key, default)
}

fun DataStore<Preferences>.putBoolean(key: String, value: Boolean) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getBoolean(key: String, default: Boolean = false): Boolean {
    return DataStoreUtils.getData(key, default)
}

fun DataStore<Preferences>.putInt(key: String, value: Int) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getInt(key: String): Int {
    return DataStoreUtils.getData(key, 0)
}

fun DataStore<Preferences>.putFloat(key: String, value: Float) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getFloat(key: String): Float {
    return DataStoreUtils.getData(key, 0f)
}

fun DataStore<Preferences>.putDouble(key: String, value: Double) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getDouble(key: String): Double {
    return DataStoreUtils.getData(key, 0.0)
}

fun DataStore<Preferences>.putLong(key: String, value: Long) {
    DataStoreUtils.putData(key, value)
}

fun DataStore<Preferences>.getLong(key: String): Long {
    return DataStoreUtils.getData(key, 0L)
}

fun DataStore<Preferences>.clearAll() {
    DataStoreUtils.clearData()
}




