package com.yidian.common.utils

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

/**
 * @description: 本地存储类（可切用户）
 * @author: huyajun
 * @date:  2021/4/27
 **/
class StorageUtil {

    var scopeStore: MMKV? = null
        private set(value) {
            field = value
        }

    var userStore: MMKV? = null
        private set(value) {
            field = value
        }


    companion object {
        @JvmStatic
        val INSTANCE: StorageUtil by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            StorageUtil()
        }
    }

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

    /**
     * 切圈
     * @param scopeName appid +城市名
     */
    fun switchScope(scopeName: String) {
        scopeStore = MMKV.mmkvWithID(scopeName)
    }

    /**
     * 切用户
     * @param userId 用户id
     */
    fun switchUser(userId: String) {
        userStore = MMKV.mmkvWithID(userId)
    }


}


val StorageManager = StorageUtil.INSTANCE