import { isJsonRecord, missingScopes, readChannelConversationKind, readChannelLifecycleAction, scopeMatches, } from '@pellux/goodvibes-sdk/platform/daemon/http/route-helpers';
export { isJsonRecord, missingScopes, readChannelConversationKind, readChannelLifecycleAction, scopeMatches, } from '@pellux/goodvibes-sdk/platform/daemon/http/route-helpers';
export function readStringList(value) {
    if (Array.isArray(value)) {
        return value
            .filter((entry) => typeof entry === 'string' && entry.trim().length > 0)
            .map((entry) => entry.trim());
    }
    if (typeof value === 'string') {
        return value.split(',').map((entry) => entry.trim()).filter((entry) => entry.length > 0);
    }
    return undefined;
}
export function resolveGatewayPathTemplate(template, query, body) {
    const bodyRecord = isJsonRecord(body) ? body : null;
    const missingParams = [];
    const path = template.replace(/\{([^}]+)\}/g, (_full, rawKey) => {
        const key = rawKey.trim();
        const queryValue = query?.[key];
        const bodyValue = bodyRecord?.[key];
        const value = typeof queryValue === 'string' || typeof queryValue === 'number'
            ? queryValue
            : typeof bodyValue === 'string' || typeof bodyValue === 'number'
                ? bodyValue
                : null;
        if (value === null) {
            missingParams.push(key);
            return `{${key}}`;
        }
        return encodeURIComponent(String(value));
    });
    return missingParams.length > 0 ? { path: null, missing: missingParams } : { path, missing: [] };
}
export function readAutomationWakeMode(value) {
    return value === 'now' || value === 'next-heartbeat' ? value : undefined;
}
export function readAutomationReasoningEffort(value) {
    return value === 'instant' || value === 'low' || value === 'medium' || value === 'high' ? value : undefined;
}
export function readExternalContentSource(value) {
    if (typeof value === 'string' && value.trim().length > 0) {
        return value.trim();
    }
    if (value && typeof value === 'object') {
        return value;
    }
    return undefined;
}
