/**
 * @internal
 * consistency/parse-plan.mjs — normalize implementation_plan.json (C15).
 *
 * Input: parsed JSON object (or null/undefined).
 * Output:
 *   {
 *     subtasks: [{id, title, acceptance_criteria: string[]}],
 *     dimensions_covered: Record<axis, {crossed: boolean, values?: object|string[], reason?: string}>
 *   }
 *
 * Legacy alias: `dimensions_crossed` is accepted as a synonym for
 * `dimensions_covered`.
 */
/**
 * @param {object | null | undefined} plan
 * @returns {{
 *   subtasks: Array<{id: string, title: string, acceptance_criteria: string[]}>,
 *   dimensions_covered: Record<string, {crossed: boolean, values?: unknown, reason?: string}>
 * }}
 */
export function parsePlan(plan) {
    if (!plan || typeof plan !== 'object') {
        return { subtasks: [], dimensions_covered: {} };
    }
    const rawSubtasks = Array.isArray(plan.subtasks) ? plan.subtasks : [];
    const subtasks = rawSubtasks.map((s) => normalizeSubtask(s));
    const rawDims = (plan.dimensions_covered && typeof plan.dimensions_covered === 'object'
        ? plan.dimensions_covered
        : null) ??
        (plan.dimensions_crossed && typeof plan.dimensions_crossed === 'object'
            ? plan.dimensions_crossed
            : null) ??
        {};
    const dimensions_covered = {};
    for (const [axis, value] of Object.entries(rawDims)) {
        if (!value || typeof value !== 'object')
            continue;
        const crossed = value.crossed === true;
        const entry = { crossed };
        if (value.values !== undefined)
            entry.values = value.values;
        if (typeof value.reason === 'string')
            entry.reason = value.reason;
        dimensions_covered[axis] = entry;
    }
    return { subtasks, dimensions_covered };
}
function normalizeSubtask(s) {
    if (!s || typeof s !== 'object') {
        return { id: '', title: '', acceptance_criteria: [] };
    }
    const id = typeof s.id === 'string' ? s.id : s.id != null ? String(s.id) : '';
    const title = typeof s.title === 'string' ? s.title : '';
    const ac = Array.isArray(s.acceptance_criteria)
        ? s.acceptance_criteria.filter((x) => typeof x === 'string')
        : [];
    return { id, title, acceptance_criteria: ac };
}
//# sourceMappingURL=parse-plan.mjs.map