// In-memory `expo-secure-store` stand-in for jest. The production module
// exposes both synchronous (`getItem`/`setItem`) and async
// (`deleteItemAsync`) entry points; `secureStore` in src/state/storage.ts
// uses the sync entry points for reads and the async one for deletes.
//
// Variables consumed inside `jest.mock` factories must be prefixed `mock*`
// (jest's hoisting allow-list), so callers should bind the returned store as
// `const mockSecure = createSecureStoreMock()` at the top of the test file.

export type SecureStoreMock = {
  getItem: (key: string) => string | null
  setItem: (key: string, value: string) => void
  deleteItemAsync: (key: string) => Promise<void>
  reset: () => void
  has: (key: string) => boolean
  dump: () => Record<string, string>
}

export function createSecureStoreMock(): SecureStoreMock {
  const store = new Map<string, string>()
  return {
    getItem: (key) => store.get(key) ?? null,
    setItem: (key, value) => {
      store.set(key, value)
    },
    deleteItemAsync: async (key) => {
      store.delete(key)
    },
    reset: () => store.clear(),
    has: (key) => store.has(key),
    dump: () => Object.fromEntries(store.entries()),
  }
}
