package com.ytpm.hydtw.utils

import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.SPUtils
import com.ytpm.hydtw.dao.Record
import com.ytpm.hydtw.dao.UserInfo

class UserInfoSpUtils {

    fun putUserInfo(userInfo: UserInfo) {
        val userJson = GsonUtils.toJson(userInfo)
        SPUtils.getInstance().put("userInfo", userJson)
    }

    fun getUserInfo(): UserInfo {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo
    }

    fun changeValue(userInfo: UserInfo) {
        val userJson = GsonUtils.toJson(userInfo)
        SPUtils.getInstance().put("userInfo", userJson)
    }

    fun getUserId(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.userId
    }

    fun getHeadImg(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.headImg
    }

    fun getNickName(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.nickName
    }

    fun getRegistryTime(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.registryTime
    }

    fun getLoginTime(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.lastLoginTime
    }

    fun getPower(): Int {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.power
    }

    fun getLastQuestionId(): String {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.lastQuestionId
    }

    fun getTodayAnswerCount(): Int {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.todayAnswerCount
    }

    fun getHistoryAnswerCount(): Int {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.historyAnswerCount
    }

    fun getAnswerRecordList(): List<Record> {
        val userJson = SPUtils.getInstance().getString("userInfo")
        val userInfo = GsonUtils.fromJson(userJson, UserInfo::class.java)
        return userInfo.answerRecordList
    }

}