const KEYS = {
  tenantId: 'haixun.tenant_id',
  accessToken: 'haixun.access_token',
  refreshToken: 'haixun.refresh_token',
  uid: 'haixun.uid',
  aiProviderToken: 'haixun.ai_provider_token',
  activeThreadsAccountId: 'haixun.active_threads_account_id',
} as const

export const storage = {
  getTenantId: () => localStorage.getItem(KEYS.tenantId) ?? '',
  setTenantId: (v: string) => localStorage.setItem(KEYS.tenantId, v),
  getAccessToken: () => localStorage.getItem(KEYS.accessToken) ?? '',
  setAccessToken: (v: string) => localStorage.setItem(KEYS.accessToken, v),
  getRefreshToken: () => localStorage.getItem(KEYS.refreshToken) ?? '',
  setRefreshToken: (v: string) => localStorage.setItem(KEYS.refreshToken, v),
  getUid: () => localStorage.getItem(KEYS.uid) ?? '',
  setUid: (v: string) => localStorage.setItem(KEYS.uid, v),
  getAiProviderToken: () => localStorage.getItem(KEYS.aiProviderToken) ?? '',
  setAiProviderToken: (v: string) => localStorage.setItem(KEYS.aiProviderToken, v),
  getActiveThreadsAccountId: () => localStorage.getItem(KEYS.activeThreadsAccountId) ?? '',
  setActiveThreadsAccountId: (v: string) => localStorage.setItem(KEYS.activeThreadsAccountId, v),
  clearSession: () => {
    localStorage.removeItem(KEYS.accessToken)
    localStorage.removeItem(KEYS.refreshToken)
    localStorage.removeItem(KEYS.uid)
    localStorage.removeItem(KEYS.activeThreadsAccountId)
  },
}