package com.doverfuelingsolutions.issp.data

import com.doverfuelingsolutions.issp.utils.DeviceUtil
import com.doverfuelingsolutions.issp.utils.TimeUtil
import com.doverfuelingsolutions.issp.utils.log.DFSLog
import com.doverfuelingsolutions.issp.utils.sp.SPKeys

/**
 * 这个工具是试验性的东西，主要目的是：对于轻量数据，就不需要过于频繁地读取，存内存即可
 */
object GlobalData {

    val serialNumber = GlobalDataProvider(DeviceUtil.generateSerialNumber(), SPKeys.SN)

    var isLogin = false
    val accountName = GlobalDataProvider("", SPKeys.ACCOUNT_NAME)
    val password = GlobalDataProvider("", SPKeys.PASSWORD)
    val accessToken = GlobalDataProvider("", SPKeys.ACCESS_TOKEN)
    val accessTokenExpire = GlobalDataProvider(0L, SPKeys.ACCESS_TOKEN_EXPIRE)

    val businessId = GlobalDataProvider("", SPKeys.BU_ID)
    val businessName = GlobalDataProvider("", SPKeys.BU_NAME)
    val stationTel = GlobalDataProvider("", SPKeys.STATION_TEL)
    val stationLogoFileName = GlobalDataProvider("", SPKeys.STATION_LOGO_FILE)

    val paymentId = GlobalDataProvider(-1, SPKeys.PAYMENT_ID)
    val paymentName = GlobalDataProvider("", SPKeys.PAYMENT_NAME)

    fun init() {
        val localTokenExpireMoment = accessTokenExpire.get()
        if (localTokenExpireMoment > 0) {
            DFSLog.d("loginToken will expire at ${TimeUtil.dateFormat(localTokenExpireMoment)}")
        }
        isLogin = System.currentTimeMillis() < localTokenExpireMoment
    }
}