import cache from '@/plugins/cache'

const SHOP_ID_KEY = 'sellerShopId'
const SHOP_NAME_KEY = 'sellerShopName'

/** 读取当前店铺 ID（写入 X-Shop-Id 请求头） */
export function getSellerShopId() {
  return cache.session.get(SHOP_ID_KEY)
}

/** 读取当前店铺名称 */
export function getSellerShopName() {
  return cache.session.get(SHOP_NAME_KEY)
}

/** 缓存商家端当前店铺上下文 */
export function setSellerShopContext(shopId, shopName) {
  if (shopId != null) {
    cache.session.set(SHOP_ID_KEY, String(shopId))
  }
  if (shopName) {
    cache.session.set(SHOP_NAME_KEY, shopName)
  }
}

/** 商家端接口公共请求头 */
export function sellerShopHeaders() {
  const shopId = getSellerShopId()
  if (shopId) {
    return { 'X-Shop-Id': shopId }
  }
  return {}
}
