import { dispatchHookEvent } from '../../../tools/manage-hooks.js';
import { buildStatusChangePayload } from '../../hooks/triggers.js';
import { withAudit } from '../../autopilot/audit-logger.js';
async function handler(ctx) {
    const { projectPath, projectId, specId, spec, newStatus, currentStatus } = ctx;
    const payload = buildStatusChangePayload(projectId, specId, spec.title, currentStatus, newStatus);
    if (projectPath) {
        await withAudit(projectPath, `update_status(${newStatus})`, 'dispatchHookEvent', () => dispatchHookEvent(projectId, payload)).catch((err) => {
            console.error('[planu] dispatchHookEvent failed:', err);
        });
    }
    else {
        await dispatchHookEvent(projectId, payload).catch((err) => {
            console.error('[planu] dispatchHookEvent failed:', err);
        });
    }
}
export const dispatchHookEventHook = {
    id: 'dispatch-hook-event',
    triggers: [], // any status change
    requiresProjectPath: false,
    label: 'Dispatch on_spec_status_change hook event (generic)',
    handler,
};
//# sourceMappingURL=dispatch-hook-event.hook.js.map