import { TOKEN_KEY } from '/@/enums/cacheEnum'

export function getToken() {
    return getAuthCache(TOKEN_KEY)
}

export function getAuthCache(key: string): string | null {
    let value: string | null = null

    // #ifdef APP-PLUS
    value = plus.storage.getItem(key)
    // #endif
    // #ifndef APP-PLUS
    try {
        value = uni.getStorageSync(key)
        if (value) {
            return value
        }
    } catch (e) {}
    // #endif

    return value
}

export function setAuthCache(key: string, value: string) {
    // #ifdef APP-PLUS
    plus.storage.setItem(key, value)
    // #endif
    // #ifndef APP-PLUS
    try {
        uni.setStorageSync(key, value)
    } catch (e) {}
    // #endif
}

export function clearAuthCache() {
    // #ifdef APP-PLUS
    plus.storage.clear()
    // #endif
    // #ifndef APP-PLUS
    try {
        uni.clearStorageSync()
    } catch (e) {}
    // #endif
}
