// src/platform/core/string-helpers.ts
function safeExcerpt(content, limit = 3e3) {
  if (!content) {
    return "";
  }
  if (content.length <= limit) {
    return content;
  }
  return `${content.slice(0, limit)}
... (truncated ${content.length - limit} chars)`;
}

// src/features/mcp/infrastructure/runtime.ts
var MCP_SERVICE_ORDER = ["codex", "gemini", "claude"];

// src/features/talk-to-figma/application/report.ts
function sortServiceResults(serviceResults) {
  return [...serviceResults].sort(
    (left, right) => MCP_SERVICE_ORDER.indexOf(left.service) - MCP_SERVICE_ORDER.indexOf(right.service)
  );
}
function formatServiceResultsMarkdown(serviceResults) {
  if (serviceResults.length === 0) {
    return "- \uC774\uBC88 \uC2E4\uD589\uC5D0\uC11C \uCD94\uAC00 \uB3D9\uAE30\uD654\uB294 \uC5C6\uC5C8\uC2B5\uB2C8\uB2E4.";
  }
  return sortServiceResults(serviceResults).map((result) => `- ${result.service}: \`${result.ok ? "\uC131\uACF5" : "\uC2E4\uD328"}${result.skipped ? " (\uC0DD\uB7B5)" : ""}\` - ${result.detail}`).join("\n");
}
function formatHealthCheckMarkdown(healthCheck) {
  return [
    `- ${healthCheck.endpoint.label}: \`${healthCheck.endpoint.ok}\``,
    `- detail: ${healthCheck.endpoint.detail}`,
    "",
    "### \uC11C\uBE44\uC2A4\uBCC4 \uC124\uC815 \uC0C1\uD0DC",
    ...sortServiceResults(healthCheck.services).map(
      (result) => `- ${result.service}: \`${result.ok ? "\uC124\uC815\uB428" : "\uB204\uB77D\uB428"}\` - ${result.detail}`
    )
  ].join("\n");
}
function formatTalkToFigmaRequestMarkdown(request) {
  return [
    `- port: \`${request.port}\``,
    `- channelName: \`${request.channelName}\``,
    "",
    "### \uC0AC\uC6A9\uC790 \uD504\uB86C\uD504\uD2B8",
    request.prompt
  ].join("\n");
}
function formatTalkToFigmaPortHealthMarkdown(portHealth) {
  return [
    `- ok: \`${portHealth.ok}\``,
    `- port: \`${portHealth.port}\``,
    `- host: \`${portHealth.host || "-"}\``,
    `- detail: ${portHealth.detail}`
  ].join("\n");
}
function formatTalkToFigmaExecutionMarkdown(executions) {
  if (executions.length === 0) {
    return "- \uC2E4\uD589\uD55C \uB3C4\uAD6C\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.";
  }
  return executions.map(
    (execution) => [
      `### Step ${execution.step} - ${execution.toolName}`,
      `- origin: \`${execution.origin}\``,
      `- ok: \`${execution.ok}\``,
      `- arguments: \`${JSON.stringify(execution.arguments)}\``,
      "",
      "[\uACB0\uACFC]",
      safeExcerpt(execution.resultText, 3e3)
    ].join("\n")
  ).join("\n\n");
}
function buildTalkToFigmaOutput(finalResult, executions, portHealth) {
  return [
    "## \uC218\uD589 \uACB0\uACFC",
    finalResult.summary,
    "",
    "## \uD3EC\uD2B8 \uC0C1\uD0DC",
    formatTalkToFigmaPortHealthMarkdown(portHealth),
    "",
    "## \uC2E4\uD589\uD55C TalkToFigma \uB3C4\uAD6C",
    formatTalkToFigmaExecutionMarkdown(executions),
    ...finalResult.changedNodes.length > 0 ? [
      "",
      "## \uBCC0\uACBD\uD55C \uB178\uB4DC",
      ...finalResult.changedNodes.map((nodeId) => `- ${nodeId}`)
    ] : [],
    ...finalResult.pendingIssues.length > 0 ? [
      "",
      "## \uD655\uC778 \uD544\uC694",
      ...finalResult.pendingIssues.map((issue) => `- ${issue}`)
    ] : []
  ].join("\n");
}

export { buildTalkToFigmaOutput, formatHealthCheckMarkdown, formatServiceResultsMarkdown, formatTalkToFigmaExecutionMarkdown, formatTalkToFigmaPortHealthMarkdown, formatTalkToFigmaRequestMarkdown };
