// engine/spec-hooks-engine.ts — SPEC-368: Spec lifecycle hook dispatch logic
function matchesFilter(hook, ctx) {
    const f = hook.filter;
    if (!f) {
        return true;
    }
    if (f.fromStatus !== undefined && f.fromStatus !== ctx.fromStatus) {
        return false;
    }
    if (f.toStatus !== undefined && f.toStatus !== ctx.toStatus) {
        return false;
    }
    if (f.priority !== undefined && f.priority !== ctx.priority) {
        return false;
    }
    if (f.tags !== undefined && f.tags.length > 0) {
        const ctxTags = ctx.tags ?? [];
        const hasTag = f.tags.some((t) => ctxTags.includes(t));
        if (!hasTag) {
            return false;
        }
    }
    return true;
}
/**
 * Describe what hooks would be triggered for a given event context.
 * Does NOT execute any side effects — purely descriptive.
 * Receives the hooks config from the caller (handler loads from storage).
 */
export function dispatchSpecHooks(ctx, config) {
    const triggered = [];
    const skipped = [];
    for (const hook of config.hooks) {
        if (hook.event !== ctx.event) {
            skipped.push(`${hook.name} (event mismatch: ${hook.event} != ${ctx.event})`);
            continue;
        }
        if (!hook.enabled) {
            skipped.push(`${hook.name} (disabled)`);
            continue;
        }
        if (!matchesFilter(hook, ctx)) {
            skipped.push(`${hook.name} (filter mismatch)`);
            continue;
        }
        triggered.push(hook.name);
    }
    const lines = [`Event: ${ctx.event} on spec ${ctx.specId}`];
    if (triggered.length > 0) {
        lines.push(`Would trigger (${triggered.length}): ${triggered.join(', ')}`);
    }
    else {
        lines.push('No hooks would trigger.');
    }
    if (skipped.length > 0) {
        lines.push(`Skipped (${skipped.length}): ${skipped.join('; ')}`);
    }
    return {
        triggered,
        skipped,
        description: lines.join('\n'),
    };
}
/**
 * Describe what actions a specific hook would perform for a spec.
 */
export function describeHookActions(hook, specId) {
    const actionDescriptions = {
        'challenge-spec': `Run challenge_spec on ${specId} to stress-test acceptance criteria`,
        'check-readiness': `Run check_readiness on ${specId} to verify detail level`,
        'notify-slack': `Send a Slack notification about ${specId} status change`,
        'create-git-branch': `Create git branch feat/${specId.toLowerCase()}-implementation`,
        'generate-changelog': `Generate changelog entry for ${specId}`,
        'send-email-digest': `Include ${specId} in next email digest`,
        'run-validate': `Run validate on ${specId} to check implementation compliance`,
    };
    return actionDescriptions[hook.action] ?? `Execute action: ${hook.action}`;
}
//# sourceMappingURL=spec-hooks-engine.js.map