package com.doverfuelingsolutions.issp.data

import com.doverfuelingsolutions.issp.utils.DeviceUtil
import com.doverfuelingsolutions.issp.utils.log.DFSLog
import com.doverfuelingsolutions.issp.utils.sp.SPKeys
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
import kotlin.properties.ObservableProperty

object DataStore {

    val sn = DeviceUtil.querySN()
    val snRaw = DeviceUtil.rawSN()

    var accountName = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.ACCOUNT_NAME, value)
        }
    var password = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.PASSWORD, value)
        }
    var accessToken = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.ACCESS_TOKEN, value)
        }
    var accessTokenExpire = 0L
        set(value) {
            field = value
            SPUtil.putLong(SPKeys.ACCESS_TOKEN_EXPIRE, value)
        }
    var buId = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.BU_ID, value)
        }
    var buName = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.BU_NAME, value)
        }
    var stationTel = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.STATION_TEL, value)
        }
    var stationLogoFile = ""
        set(value) {
            field = value
            SPUtil.putString(SPKeys.STATION_LOGO_FILE, value)
        }

    fun init() {
        accountName = SPUtil.getString(SPKeys.ACCOUNT_NAME, "")
        password = SPUtil.getString(SPKeys.PASSWORD, "")
        accessToken = SPUtil.getString(SPKeys.ACCESS_TOKEN, "")
        buId = SPUtil.getString(SPKeys.BU_ID, "")
        buName = SPUtil.getString(SPKeys.BU_NAME, "")
        accessTokenExpire = SPUtil.getLong(SPKeys.ACCESS_TOKEN_EXPIRE)
        stationTel = SPUtil.getString(SPKeys.STATION_TEL, "")
        stationLogoFile = SPUtil.getString(SPKeys.STATION_LOGO_FILE, "")
    }
}