import type { HealthReporter, HealthSnapshot, HealthStatus, Metrics } from './contracts.js'

export function createHealthReporter(workerId: string, now: () => Date = () => new Date()): HealthReporter {
  const startedAt = now()
  let status: HealthStatus = 'starting'
  let detail: string | undefined
  return {
    setStatus(next, nextDetail) {
      status = next
      detail = nextDetail
    },
    snapshot(): HealthSnapshot {
      return { status, workerId, startedAt, checkedAt: now(), ...(detail === undefined ? {} : { detail }) }
    },
  }
}

export const noopMetrics: Metrics = Object.freeze({
  increment() {},
  observe() {},
})
