package com.gamedog.vididin.core.login.login

import com.ama.core.architecture.util.DateUtil
import com.ama.core.architecture.util.DeviceUtil
import com.ama.core.architecture.util.SpUtil
import com.gamedog.vididin.beans.Account



object AccountManager {

    private val mAccount: Account? by lazy {
        var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
        if (account == null) {
            val deviceUUId = DeviceUtil.generateDeviceId()
            account = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
            account.let {
                SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, account)
            }
        }
        account
    }

    fun getAccount() : Account? {
        return mAccount
    }

    /*fun initAccount() : Account {
        AsyncUtil.doGlobalAsync({
            SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
        }, onComplete = { item->
            mAccount = item
            if (mAccount == null) {
                val deviceUUId = DeviceUtil.generateDeviceId()
                mAccount = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
            }
        })
    }*/


}

