// Planu — Validator: spec quality checklist generator
import { validateScopeDifficulty } from './analyzer.js';
/**
 * Generate a quality checklist for a spec.
 */
export function generateChecklist(spec, focus = []) {
    const allItems = getChecklistItems(spec);
    const items = focus.length > 0 ? allItems.filter((item) => focus.includes(item.category)) : allItems;
    const passedCount = items.filter((i) => i.answer === 'yes').length;
    const totalCount = items.length;
    const score = totalCount > 0 ? Math.round((passedCount / totalCount) * 100) : 0;
    return {
        specId: spec.id,
        items,
        passedCount,
        totalCount,
        score,
        generatedAt: new Date().toISOString(),
    };
}
function buildCompletenessItems(spec) {
    return [
        {
            id: 'cl-comp-1',
            question: 'Does the spec have clear acceptance criteria?',
            category: 'completeness',
            answer: spec.specPath ? 'pending' : 'no',
            autoChecked: false,
        },
        {
            id: 'cl-comp-2',
            question: 'Is the technical design documented in spec.md under ## Technical?',
            category: 'completeness',
            answer: spec.technicalPath ? 'pending' : 'no',
            autoChecked: false,
        },
        {
            id: 'cl-comp-3',
            question: 'Are all dependencies identified?',
            category: 'completeness',
            answer: 'pending',
            autoChecked: false,
        },
    ];
}
function buildConsistencyItems(spec) {
    return [
        {
            id: 'cl-cons-1',
            question: 'Is the scope consistent with the estimated difficulty?',
            category: 'consistency',
            answer: validateScopeDifficulty(spec.scope, spec.difficulty) ? 'yes' : 'no',
            autoChecked: true,
        },
        {
            id: 'cl-cons-2',
            question: 'Is the type consistent with the description?',
            category: 'consistency',
            answer: 'pending',
            autoChecked: false,
        },
    ];
}
function buildFeasibilityItems(spec) {
    return [
        {
            id: 'cl-feas-1',
            question: 'Are the estimated hours realistic for the scope?',
            category: 'feasibility',
            answer: 'pending',
            autoChecked: false,
        },
        {
            id: 'cl-feas-2',
            question: 'Are there any known technical blockers?',
            category: 'feasibility',
            answer: spec.blockedBy.length === 0 ? 'yes' : 'no',
            autoChecked: true,
        },
    ];
}
function buildSecurityAndEdgeItems() {
    return [
        {
            id: 'cl-sec-1',
            question: 'Are security implications considered?',
            category: 'security',
            answer: 'pending',
            autoChecked: false,
        },
        {
            id: 'cl-sec-2',
            question: 'Does the spec handle authentication/authorization correctly?',
            category: 'security',
            answer: 'pending',
            autoChecked: false,
        },
        {
            id: 'cl-edge-1',
            question: 'Are error states and edge cases documented?',
            category: 'edge-cases',
            answer: 'pending',
            autoChecked: false,
        },
        {
            id: 'cl-edge-2',
            question: 'Are race conditions or concurrency issues addressed?',
            category: 'edge-cases',
            answer: 'pending',
            autoChecked: false,
        },
    ];
}
function buildUxItems() {
    return [
        {
            id: 'cl-ux-1',
            question: 'Are loading and error states defined?',
            category: 'ux',
            answer: 'pending',
            autoChecked: false,
        },
        {
            id: 'cl-ux-2',
            question: 'Is the feature accessible (WCAG compliant)?',
            category: 'ux',
            answer: 'pending',
            autoChecked: false,
        },
    ];
}
/**
 * Build all checklist items for a spec.
 */
export function getChecklistItems(spec) {
    const items = [
        ...buildCompletenessItems(spec),
        ...buildConsistencyItems(spec),
        ...buildFeasibilityItems(spec),
        ...buildSecurityAndEdgeItems(),
    ];
    if (spec.target === 'frontend' || spec.target === 'fullstack') {
        items.push(...buildUxItems());
    }
    return items;
}
//# sourceMappingURL=checklist.js.map