import { docusign } from "./docusign"
import { dropboxSign } from "./dropbox-sign"
import type { ESignAdapter, ESignProvider } from "./types"

// Adapter registry — dependency-free (no db) so it can be imported anywhere,
// including the credential resolver, without creating import cycles.
const ADAPTERS: Record<ESignProvider, ESignAdapter> = { docusign, dropbox_sign: dropboxSign }

export function getAdapter(id: string): ESignAdapter | null {
  return id === "docusign" || id === "dropbox_sign" ? ADAPTERS[id] : null
}

/** Providers the platform can offer, with their connect style + availability. */
export function listEsignAdapters() {
  return (Object.keys(ADAPTERS) as ESignProvider[]).map((id) => ({
    id,
    label: ADAPTERS[id].label,
    kind: ADAPTERS[id].kind,
    available: ADAPTERS[id].available(),
  }))
}
