// engine/spec-format/criteria-parser.ts — Unified criteria parser for lean specs (SPEC-481)
// Reads both criteria: (checkbox) and scenarios: (BDD) from parsed YAML frontmatter.
/**
 * Parses both checkbox criteria and BDD scenarios from a YAML frontmatter object.
 * Consumers (validate, check_readiness, challenge_spec) can treat both formats uniformly.
 *
 * @param frontmatter - Parsed YAML object (e.g., from js-yaml or similar)
 */
export function parseSpecCriteria(frontmatter) {
    const checkboxes = parseCriteriaArray(frontmatter.criteria);
    const scenarios = parseScenariosArray(frontmatter.scenarios);
    return { checkboxes, scenarios };
}
function parseCriteriaArray(raw) {
    if (!Array.isArray(raw)) {
        return [];
    }
    const result = [];
    for (const item of raw) {
        if (typeof item !== 'object' || item === null) {
            continue;
        }
        const obj = item;
        const text = typeof obj.text === 'string' ? obj.text : '';
        const done = obj.done === true;
        if (text) {
            result.push({ text, done });
        }
    }
    return result;
}
function parseScenariosArray(raw) {
    if (!Array.isArray(raw)) {
        return [];
    }
    const result = [];
    for (const item of raw) {
        if (typeof item !== 'object' || item === null) {
            continue;
        }
        const obj = item;
        const title = typeof obj.title === 'string' ? obj.title : '';
        const done = obj.done === true;
        const steps = parseStepsArray(obj.steps);
        if (title) {
            result.push({ title, steps, done });
        }
    }
    return result;
}
function parseStepsArray(raw) {
    if (!Array.isArray(raw)) {
        return [];
    }
    const validKeywords = new Set(['given', 'when', 'then', 'and']);
    const result = [];
    for (const item of raw) {
        if (typeof item !== 'object' || item === null) {
            continue;
        }
        const obj = item;
        const keyword = typeof obj.keyword === 'string' ? obj.keyword.toLowerCase() : '';
        const text = typeof obj.text === 'string' ? obj.text : '';
        if (validKeywords.has(keyword) && text) {
            result.push({ keyword: keyword, text });
        }
    }
    return result;
}
//# sourceMappingURL=criteria-parser.js.map