import { CART_CHECKOUT_STORAGE_KEY } from '@/constants/cart'

/** 缓存去结算预校验结果，供后续确认订单页读取 */
export function saveCheckoutPrepare(data) {
  if (!data) return
  try {
    uni.setStorageSync(CART_CHECKOUT_STORAGE_KEY, data)
  } catch (e) {
    // ignore
  }
}

export function readCheckoutPrepare() {
  try {
    return uni.getStorageSync(CART_CHECKOUT_STORAGE_KEY) || null
  } catch (e) {
    return null
  }
}

export function clearCheckoutPrepare() {
  try {
    uni.removeStorageSync(CART_CHECKOUT_STORAGE_KEY)
  } catch (e) {
    // ignore
  }
}
