/**
 * commerce-storefront blueprint · wiring seam for `@platform-modules/mail`.
 *
 * Capture adapter for tests — records sends verbatim so the composition proof can assert order
 * confirmation mail was emitted.
 */
import { createMail, type MailAdapter, type MailMessage } from '@platform-modules/mail'
import type { CapturedMail } from '@platform-modules/mail/capture'

export type StorefrontMailer = {
  adapter: MailAdapter
  mail: ReturnType<typeof createMail>
  captured: CapturedMail[]
}

export function createStorefrontMailer(): StorefrontMailer {
  const captured: CapturedMail[] = []
  const adapter: MailAdapter = {
    async send(msg) {
      captured.push(msg)
      return { id: `cap-${captured.length}`, provider: 'capture' }
    },
  }
  return { adapter, mail: createMail(adapter), captured }
}

export type { MailMessage }
