// ---------------------------------------------------------------------------
// Payload builders
// ---------------------------------------------------------------------------
/**
 * Build a rich Block Kit payload for a spec status change notification.
 */
export function buildSpecPayload(specId, title, oldStatus, newStatus) {
    const fallbackText = `:white_check_mark: ${specId} status changed: ${oldStatus} → ${newStatus}`;
    const blocks = [
        {
            type: 'header',
            text: {
                type: 'plain_text',
                text: `:white_check_mark: ${specId} status changed`,
                emoji: true,
            },
        },
        {
            type: 'section',
            fields: [
                {
                    type: 'mrkdwn',
                    text: `*Spec ID*\n${specId}`,
                },
                {
                    type: 'mrkdwn',
                    text: `*Title*\n${title}`,
                },
                {
                    type: 'mrkdwn',
                    text: `*Status*\n${oldStatus} → ${newStatus}`,
                },
            ],
        },
    ];
    return { text: fallbackText, blocks };
}
/**
 * Build a plain or spec-linked manual message payload.
 */
export function buildManualPayload(message, specId) {
    const prefix = specId !== undefined ? `[${specId}] ` : '';
    const text = `${prefix}${message}`;
    const blocks = [
        {
            type: 'section',
            text: {
                type: 'mrkdwn',
                text,
            },
        },
    ];
    return { text, blocks };
}
// ---------------------------------------------------------------------------
// HTTP dispatcher
// ---------------------------------------------------------------------------
/**
 * POST a Slack payload to an incoming webhook URL.
 * Throws if the HTTP response is not OK (2xx).
 */
export async function dispatchToSlack(webhookUrl, payload) {
    const response = await globalThis.fetch(webhookUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(payload),
        signal: AbortSignal.timeout(10_000),
    });
    if (!response.ok) {
        const body = await response.text().catch(() => '(unreadable)');
        throw new Error(`Slack webhook returned ${response.status}: ${body}. Check the webhook URL and try again.`);
    }
}
//# sourceMappingURL=slack-dispatcher.js.map