export type McpDialogStatus = Readonly<{
  state: 'idle' | 'testing' | 'success' | 'error'
  message?: string
  results?: ReadonlyArray<{
    name: string
    toolCount?: number
    error?: string
    disabled?: boolean
  }>
}>

export type McpDialogLintStatus = Readonly<{
  state: 'idle' | 'success' | 'error'
  message?: string
}>

export function formatMcpStatusLines(
  status: McpDialogStatus,
  lint: McpDialogLintStatus,
  strings: Readonly<{
    lint?: string
    status: string
    tools: string
    disabled: string
  }>,
): string[] {
  const lines: string[] = []
  if (lint.message && strings.lint) lines.push(`${strings.lint}: ${lint.message}`)

  if (status.message) lines.push(`${strings.status}: ${status.message}`)

  if (status.results?.length) {
    for (const result of status.results) {
      if (result.disabled) {
        lines.push(`${result.name}: ${strings.disabled}`)
      } else if (result.error) {
        lines.push(`${result.name}: ${result.error}`)
      } else if (typeof result.toolCount === 'number') {
        lines.push(`${result.name}: ${strings.tools} ${result.toolCount}`)
      }
    }
  }

  return lines
}
