import { buildNativeReqOutboundCompatAdapterContext } from '../../hub/pipeline/compat/native-adapter-context.js';
import { runReqOutboundStage3CompatWithNative, runRespInboundStage3CompatWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
const PROFILE = 'chat:qwen';
const DEFAULT_PROVIDER_PROTOCOL = 'openai-chat';
const DEFAULT_ENTRY_ENDPOINT = '/v1/chat/completions';
function buildQwenCompatContext(adapterContext) {
    const nativeContext = buildNativeReqOutboundCompatAdapterContext(adapterContext);
    return {
        ...nativeContext,
        compatibilityProfile: PROFILE,
        providerProtocol: nativeContext.providerProtocol ?? adapterContext?.providerProtocol ?? DEFAULT_PROVIDER_PROTOCOL,
        entryEndpoint: nativeContext.entryEndpoint ?? adapterContext?.entryEndpoint ?? DEFAULT_ENTRY_ENDPOINT
    };
}
function buildQwenRequestCompatInput(payload, adapterContext) {
    return {
        payload,
        adapterContext: buildQwenCompatContext(adapterContext),
        explicitProfile: PROFILE
    };
}
function buildQwenResponseCompatInput(payload, adapterContext) {
    return {
        payload,
        adapterContext: buildQwenCompatContext(adapterContext),
        explicitProfile: PROFILE
    };
}
export function applyQwenRequestTransform(payload, adapterContext) {
    if (!payload || typeof payload !== 'object') {
        return payload;
    }
    return runReqOutboundStage3CompatWithNative(buildQwenRequestCompatInput(payload, adapterContext)).payload;
}
export function applyQwenResponseTransform(payload, adapterContext) {
    if (!payload || typeof payload !== 'object') {
        return payload;
    }
    return runRespInboundStage3CompatWithNative(buildQwenResponseCompatInput(payload, adapterContext)).payload;
}
