// 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/commit/domain/report.ts
function formatCommitStatusLabel(state) {
  switch (state) {
    case "success":
      return "\uC131\uACF5";
    case "no-change":
    case "skipped":
      return "\uBCC0\uACBD\uC5C6\uC74C";
    case "failure":
    default:
      return "\uC2E4\uD328";
  }
}
function buildCommitExecutionReport(options) {
  const rationale = options.rationale || "- AI \uC751\uB2F5\uC5D0\uC11C \uD310\uB2E8 \uADFC\uAC70\uB97C \uCD94\uCD9C\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.";
  const executionSummaryLines = options.commands.map((command) => `- \`${command}\``);
  if (options.state === "skipped") {
    executionSummaryLines.push("- \uD14C\uC2A4\uD2B8 \uBAA8\uB4DC\uB77C \uC2E4\uC81C `git add`, `git commit`, `git log` \uC2E4\uD589\uC740 \uC0DD\uB7B5\uD588\uB2E4.");
  }
  if (options.state === "no-change") {
    executionSummaryLines.push("- \uCD94\uCD9C \uAC00\uB2A5\uD55C \uCEE4\uBC0B \uBA54\uC2DC\uC9C0\uAC00 \uC5C6\uAC70\uB098 \uC2A4\uD14C\uC774\uC9D5 \uB300\uC0C1 \uBCC0\uACBD\uC774 \uC5C6\uC5B4 \uC0C8 \uCEE4\uBC0B\uC744 \uB9CC\uB4E4\uC9C0 \uC54A\uC558\uB2E4.");
  }
  if (options.errorMessage) {
    executionSummaryLines.push(`- \uC2E4\uD328 \uC6D0\uC778: ${options.errorMessage}`);
  }
  return [
    "## \uC218\uD589 \uACB0\uACFC",
    "",
    `- \uC0C1\uD0DC: \`${formatCommitStatusLabel(options.state)}\``,
    `- \uC0AC\uC6A9\uD55C \uCEE4\uBC0B \uBA54\uC2DC\uC9C0: ${options.message ? `\`${options.message}\`` : "(\uC5C6\uC74C)"}`,
    `- \uCEE4\uBC0B \uD574\uC2DC: ${options.commitHash ? `\`${options.commitHash}\`` : "(\uC5C6\uC74C)"}`,
    "",
    "## \uD310\uB2E8 \uADFC\uAC70",
    "",
    rationale,
    "",
    "## \uC2E4\uD589 \uC694\uC57D",
    "",
    executionSummaryLines.length > 0 ? executionSummaryLines.join("\n") : "- (\uC5C6\uC74C)"
  ].join("\n");
}
function buildCommitSummary(state, headAfter, latestCommitLog, errorMessage) {
  const latestHeadline = latestCommitLog.split("\n").find(Boolean) || "";
  if (state === "success") {
    return `\uCEE4\uBC0B \uC644\uB8CC: ${safeExcerpt(latestHeadline, 80)}`;
  }
  if (state === "skipped") {
    return `\uCEE4\uBC0B \uD14C\uC2A4\uD2B8 \uC644\uB8CC: ${headAfter ? safeExcerpt(headAfter, 12) : "\uC2E4\uC81C \uCEE4\uBC0B \uC0DD\uB7B5"}`;
  }
  if (state === "failure") {
    return `\uCEE4\uBC0B \uC2E4\uD328: ${safeExcerpt(errorMessage || latestHeadline || "\uC6D0\uC778 \uBBF8\uC0C1", 80)}`;
  }
  return latestHeadline ? `\uCEE4\uBC0B \uC2E4\uD589: \uC0C8 \uCEE4\uBC0B \uC5C6\uC74C (${safeExcerpt(latestHeadline, 60)})` : "\uCEE4\uBC0B \uC2E4\uD589: \uC0C8 \uCEE4\uBC0B \uC5C6\uC74C";
}

export { buildCommitExecutionReport, buildCommitSummary };
