package com.dlc.eboard.sp

import android.content.Context
import com.google.gson.Gson
import com.rc.core.log.RcLog
import com.rc.httpcore.vo.response.LaboratoryVo
import java.lang.Exception

/**
 * info
 *
 * @author ReiChin_
 */
object DeviceSp {

    private const val SP_NAME = "laboratory"
    private const val KEY = "lab_json_data"

    fun saveLaboratoryVo(context: Context, datas: LaboratoryVo) {
        val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        sp.edit().putString(KEY, Gson().toJson(datas)).apply()
    }

    fun loadLaboratoryVo(context: Context): LaboratoryVo? {
        return try {
            val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
            val jsonData = sp.getString(KEY, null)

            val laboratoryVo = Gson().fromJson(jsonData, LaboratoryVo::class.java)
            if (null == laboratoryVo || laboratoryVo.subId.isNullOrEmpty()) null else laboratoryVo
        } catch (e: Exception) {
            e.printStackTrace()
            null
        }
    }

}