package com.develop.food.base.utils

import android.content.Context
import android.os.Parcelable
import com.tencent.mmkv.MMKV

object MmkvUtils {

    val instance: MMKV by lazy { MMKV.defaultMMKV() }

    fun initialize(context: Context) {
        MMKV.initialize(context)
    }

    fun save(key: String, value: String?) = instance.encode(key, value)

    fun save(key: String, value: Int) = instance.encode(key, value)

    fun save(key: String, value: Boolean) = instance.encode(key, value)

    fun save(key: String, value: Float) = instance.encode(key, value)

    fun save(key: String, value: Long) = instance.encode(key, value)

    fun save(key: String, value: Set<String>) = instance.encode(key, value)

    fun save(key: String, value: Parcelable?) = instance.encode(key, value)

    fun save(key: String, value: ByteArray?) = instance.encode(key, value)

    fun getString(key: String): String? = instance.decodeString(key)

    fun getInt(key: String) = instance.decodeInt(key)

    fun getInt(key: String, defaultInt: Int) = instance.decodeInt(key, defaultInt)

    fun getFloat(key: String) = instance.decodeFloat(key)

    fun getBool(key: String) = instance.decodeBool(key)

    fun getStringSet(key: String): MutableSet<String>? = instance.decodeStringSet(key, HashSet())

    fun getDouble(key: String) = instance.decodeDouble(key)

    fun getLong(key: String) = instance.decodeLong(key)

    fun getBytes(key: String): ByteArray? = instance.decodeBytes(key)

    fun <T : Parcelable> getParcelable(key: String, clz: Class<T>): T? = instance.decodeParcelable(key, clz)

    fun clear(key: String) = instance.remove(key)

    fun getBool(key: String, default: Boolean) = instance.decodeBool(key, default)
}