/**
 * Markdown formatters for GitHub issue bodies, PR descriptions,
 * and summary comments.
 *
 * All functions produce GitHub-flavored markdown strings ready
 * for the `gh` CLI body parameters.
 */
export function formatMilestoneIssueBody(data) {
	const lines = [];
	lines.push(`# ${data.id}: ${data.title}`);
	lines.push("");
	if (data.vision) {
		lines.push("## Vision");
		lines.push(data.vision);
		lines.push("");
	}
	if (data.successCriteria?.length) {
		lines.push("## Success Criteria");
		for (const criterion of data.successCriteria) {
			lines.push(`- [ ] ${criterion}`);
		}
		lines.push("");
	}
	if (data.slices?.length) {
		lines.push("## Slices");
		lines.push("");
		lines.push("| Slice | Title | Tasks |");
		lines.push("|-------|-------|-------|");
		for (const slice of data.slices) {
			lines.push(
				`| ${slice.id} | ${slice.title} | ${slice.taskCount ?? "—"} |`,
			);
		}
		lines.push("");
	}
	lines.push("---");
	lines.push("*Auto-generated by SF GitHub Sync*");
	return lines.join("\n");
}
export function formatSlicePRBody(data) {
	const lines = [];
	lines.push(`## ${data.id}: ${data.title}`);
	lines.push("");
	if (data.goal) {
		lines.push("### Goal");
		lines.push(data.goal);
		lines.push("");
	}
	if (data.mustHaves?.length) {
		lines.push("### Must-Haves");
		for (const item of data.mustHaves) {
			lines.push(`- ${item}`);
		}
		lines.push("");
	}
	if (data.demoCriterion) {
		lines.push("### Demo Criterion");
		lines.push(data.demoCriterion);
		lines.push("");
	}
	if (data.tasks?.length) {
		lines.push("### Tasks");
		for (const task of data.tasks) {
			const ref = task.issueNumber ? ` (#${task.issueNumber})` : "";
			lines.push(`- [ ] ${task.id}: ${task.title}${ref}`);
		}
		lines.push("");
	}
	lines.push("---");
	lines.push("*Auto-generated by SF GitHub Sync*");
	return lines.join("\n");
}
export function formatTaskIssueBody(data) {
	const lines = [];
	lines.push(`## ${data.id}: ${data.title}`);
	lines.push("");
	if (data.description) {
		lines.push(data.description);
		lines.push("");
	}
	if (data.files?.length) {
		lines.push("### Files");
		for (const file of data.files) {
			lines.push(`- \`${file}\``);
		}
		lines.push("");
	}
	if (data.verifyCriteria?.length) {
		lines.push("### Verification");
		for (const criterion of data.verifyCriteria) {
			lines.push(`- [ ] ${criterion}`);
		}
		lines.push("");
	}
	return lines.join("\n");
}
export function formatSummaryComment(data) {
	const lines = [];
	if (data.oneLiner) {
		lines.push(`**Summary:** ${data.oneLiner}`);
		lines.push("");
	}
	if (data.body) {
		lines.push(data.body);
		lines.push("");
	}
	if (data.frontmatter && Object.keys(data.frontmatter).length > 0) {
		lines.push("<details>");
		lines.push("<summary>Metadata</summary>");
		lines.push("");
		lines.push("```yaml");
		for (const [key, value] of Object.entries(data.frontmatter)) {
			lines.push(`${key}: ${JSON.stringify(value)}`);
		}
		lines.push("```");
		lines.push("");
		lines.push("</details>");
	}
	return lines.join("\n");
}
