package cn.yyxx.eyuancomm.comm.entity

import org.json.JSONException
import org.json.JSONObject

/**
 * @author #Suyghur.
 * Created on 2021/06/17
 */
class SdkLoginInfo private constructor() {

    var userId = ""
    var token = ""
    var isRegUser = false
    var currentRoleId = ""
    var currentRoleName = ""
    var currentRoleLevel = ""
    var currentServerId = ""
    var currentServerName = ""

    fun reset() {
        this.userId = ""
        this.token = ""
        this.isRegUser = false
        this.currentRoleId = ""
        this.currentRoleName = ""
        this.currentRoleLevel = ""
        this.currentServerId = ""
        this.currentServerName = ""
    }

    fun toJsonString(): String {
        val jsonObject = JSONObject()
        try {
            jsonObject.put("uid", userId)
            jsonObject.put("token", token)
        } catch (e: JSONException) {
            e.printStackTrace()
        }
        return jsonObject.toString()
    }

    override fun toString(): String {
        return "SdkLoginInfo(userId='$userId', token='$token', isRegUser=$isRegUser, currentRoleId='$currentRoleId', currentRoleName='$currentRoleName', currentRoleLevel='$currentRoleLevel', currentServerId='$currentServerId', currentServerName='$currentServerName')"
    }

    companion object {
        val instance: SdkLoginInfo by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            SdkLoginInfo()
        }
    }
}