import { validate } from "toolcraft-schema";
export class FrontmatterValidationError extends Error {
    issues;
    constructor(message, issues) {
        super(message);
        this.name = "FrontmatterValidationError";
        this.issues = issues;
    }
}
export function validateFrontmatter(schema, frontmatter, mdPath) {
    const result = validate(schema, frontmatter);
    if (result.ok) {
        return result.value;
    }
    throw new FrontmatterValidationError(formatIssues(mdPath, result.issues), result.issues);
}
function formatIssues(mdPath, issues) {
    return issues
        .map((issue) => `${mdPath} (${formatPath(issue.path)}): ${issue.message}`)
        .join("\n");
}
function formatPath(path) {
    return path.join(".") || "frontmatter";
}
