// Planu — Validator: Definition of Ready and Definition of Done generators
function buildDoRSpecItems(spec) {
    return [
        {
            id: 'dor-1',
            description: 'Spec has a clear title and description',
            category: 'spec',
            required: true,
            autoCheck: true,
            status: spec.title.length > 3 ? 'passed' : 'failed',
        },
        {
            id: 'dor-2',
            description: 'Spec type and scope are defined',
            category: 'spec',
            required: true,
            autoCheck: true,
            status: spec.type.length > 0 && spec.scope.length > 0 ? 'passed' : 'failed',
        },
        {
            id: 'dor-3',
            description: 'Difficulty is assessed (1-5)',
            category: 'spec',
            required: true,
            autoCheck: true,
            status: spec.difficulty >= 1 && spec.difficulty <= 5 ? 'passed' : 'failed',
        },
        {
            id: 'dor-4',
            description: 'Estimation is complete',
            category: 'spec',
            required: true,
            autoCheck: true,
            status: spec.estimation.devHours > 0 ? 'passed' : 'failed',
        },
        {
            id: 'dor-5',
            description: 'HU.md file exists',
            category: 'spec',
            required: true,
            autoCheck: true,
            status: spec.huPath ? 'passed' : 'failed',
        },
    ];
}
function buildDoRTechnicalItems(spec) {
    return [
        {
            id: 'dor-6',
            description: 'FICHA-TECNICA.md file exists',
            category: 'design',
            required: true,
            autoCheck: true,
            status: spec.fichaTecnicaPath ? 'passed' : 'failed',
        },
        {
            id: 'dor-7',
            description: 'Dependencies are identified',
            category: 'dependencies',
            required: false,
            autoCheck: true,
            status: 'passed', // Not having deps is valid
        },
        {
            id: 'dor-8',
            description: 'No blocking dependencies',
            category: 'dependencies',
            required: true,
            autoCheck: true,
            status: spec.blockedBy.length === 0 ? 'passed' : 'failed',
        },
        {
            id: 'dor-9',
            description: 'Risk level is assessed',
            category: 'technical',
            required: true,
            autoCheck: true,
            status: spec.risk.length > 0 ? 'passed' : 'failed',
        },
        {
            id: 'dor-10',
            description: 'Target is defined (frontend/backend/fullstack)',
            category: 'technical',
            required: true,
            autoCheck: true,
            status: spec.target.length > 0 ? 'passed' : 'failed',
        },
    ];
}
function buildDoRItems(spec) {
    return [...buildDoRSpecItems(spec), ...buildDoRTechnicalItems(spec)];
}
/**
 * Generate a Definition of Ready checklist for a spec.
 */
export function generateDoR(spec) {
    const items = buildDoRItems(spec);
    const requiredItems = items.filter((i) => i.required);
    const passedCount = items.filter((i) => i.status === 'passed').length;
    const requiredCount = requiredItems.length;
    const isReady = requiredItems.every((i) => i.status === 'passed');
    return {
        specId: spec.id,
        items,
        passedCount,
        requiredCount,
        isReady,
        generatedAt: new Date().toISOString(),
    };
}
function buildDoDItems(spec, score, hasQualityIssues) {
    return [
        {
            id: 'dod-1',
            description: 'All acceptance criteria implemented',
            category: 'code',
            required: true,
            autoCheck: true,
            status: score === 100 ? 'passed' : score > 0 ? 'failed' : 'pending',
        },
        {
            id: 'dod-2',
            description: 'No critical quality issues',
            category: 'quality',
            required: true,
            autoCheck: true,
            status: !hasQualityIssues ? 'passed' : 'failed',
        },
        {
            id: 'dod-3',
            description: 'Unit tests written for new code',
            category: 'tests',
            required: true,
            autoCheck: false,
            status: 'pending',
        },
        {
            id: 'dod-4',
            description: 'Code reviewed and approved',
            category: 'review',
            required: true,
            autoCheck: false,
            status: 'pending',
        },
        {
            id: 'dod-5',
            description: 'Documentation updated',
            category: 'docs',
            required: false,
            autoCheck: false,
            status: 'pending',
        },
        {
            id: 'dod-6',
            description: 'No regressions in existing tests',
            category: 'tests',
            required: true,
            autoCheck: false,
            status: 'pending',
        },
        {
            id: 'dod-7',
            description: 'Spec status updated to done',
            category: 'code',
            required: true,
            autoCheck: true,
            status: spec.status === 'done' ? 'passed' : 'pending',
        },
        {
            id: 'dod-8',
            description: 'Actuals recorded (hours, tokens, cost)',
            category: 'review',
            required: false,
            autoCheck: true,
            status: spec.actuals ? 'passed' : 'pending',
        },
    ];
}
/**
 * Generate a Definition of Done checklist for a spec.
 */
export function generateDoD(spec, validationResult) {
    const score = validationResult?.score ?? 0;
    const hasQualityIssues = (validationResult?.qualityIssues.length ?? 0) > 0;
    const items = buildDoDItems(spec, score, hasQualityIssues);
    const requiredItems = items.filter((i) => i.required);
    const passedCount = items.filter((i) => i.status === 'passed').length;
    const requiredCount = requiredItems.length;
    const isDone = requiredItems.every((i) => i.status === 'passed');
    return {
        specId: spec.id,
        items,
        passedCount,
        requiredCount,
        isDone,
        completedAt: isDone ? new Date().toISOString() : null,
    };
}
//# sourceMappingURL=dor-dod.js.map