export function isRecord(v) {
    return !!v && typeof v === 'object' && !Array.isArray(v);
}
export function validateTriggerRequest(raw) {
    if (!isRecord(raw)) {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'bad_request', error: 'request body must be an object' } };
    }
    const source = raw.source;
    const target = raw.target;
    const envelope = raw.envelope;
    if (!isRecord(source) || !isRecord(target) || !isRecord(envelope)) {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'bad_request', error: 'source, target, and envelope are required objects' } };
    }
    if (target.kind !== 'turn' && target.kind !== 'workflow') {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'target_required', error: 'target.kind must be turn or workflow' } };
    }
    if (target.kind === 'turn' && typeof target.chatId !== 'string' && typeof target.sessionId !== 'string') {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'target_required', error: 'turn target requires chatId or sessionId' } };
    }
    if (target.kind === 'workflow' && typeof target.workflowId !== 'string') {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'target_required', error: 'workflow target requires workflowId' } };
    }
    if (typeof envelope.sourceName !== 'string' || envelope.trusted !== false) {
        return { ok: false, status: 400, body: { ok: false, errorCode: 'bad_request', error: 'envelope.sourceName is required and envelope.trusted must be false' } };
    }
    return { ok: true, request: raw };
}
//# sourceMappingURL=trigger-types.js.map