// Single chokepoint for protocol dispatch.
//
// Every call site that uses an operation defined on `ProtocolAdapter` goes
// through `activeProtocol()`. This is the ONLY place in the codebase where
// `accountType === 'mastodon' ? ... : ...` runs for protocol-adapted
// operations; the rest of the app stays type-agnostic.
//
// Add new adapters here. Add new operations to `ProtocolAdapter` in
// `./types.ts` — TypeScript will fail every adapter that doesn't implement
// them, which is the central invariant this layer maintains.

import { AccountStore } from 'src/state/accountStore'
import { mastodonAdapter } from './mastodonAdapter'
import { pixelfedAdapter } from './pixelfedAdapter'
import type { ProtocolAdapter } from './types'

/**
 * Resolve the adapter for the currently active account. Throws if no account
 * is active — every adapter call lives downstream of an authenticated UI
 * surface, so the missing-active-account case is a real bug, not a state to
 * fall back from.
 */
export function activeProtocol(): ProtocolAdapter {
  const account = AccountStore.activeAccountOrThrow()
  return account.type === 'mastodon' ? mastodonAdapter : pixelfedAdapter
}

export { normaliseTagName, parseHandle } from './handle'
export type {
  AccountLookupResult,
  AccountQueryHandle,
  Cursor,
  HashtagFeedOptions,
  HashtagFeedPage,
  ProtocolAdapter,
  ProtocolKind,
  SearchAccountsOptions,
} from './types'
