import { createNimiError } from '../errors.js';
import { ReasonCode } from '../../types/index.js';
function asBinarySerdeType(type) {
    return type;
}
export function encodeRequest(methodId, codec, request) {
    try {
        const requestType = asBinarySerdeType(codec.requestType);
        const payload = requestType.create(request);
        return requestType.toBinary(payload);
    }
    catch (error) {
        throw createNimiError({
            message: `${methodId} request encode failed: ${error instanceof Error ? error.message : String(error)}`,
            reasonCode: ReasonCode.SDK_RUNTIME_REQUEST_ENCODE_FAILED,
            actionHint: 'validate_request_payload_against_proto',
            source: 'sdk',
        });
    }
}
export function decodeUnaryResponse(methodId, codec, payload) {
    try {
        return asBinarySerdeType(codec.responseType).fromBinary(payload);
    }
    catch (error) {
        throw createNimiError({
            message: `${methodId} response decode failed: ${error instanceof Error ? error.message : String(error)}`,
            reasonCode: ReasonCode.SDK_RUNTIME_RESPONSE_DECODE_FAILED,
            actionHint: 'check_transport_payload_contract',
            source: 'sdk',
        });
    }
}
export function decodeStreamEvent(methodId, codec, payload) {
    try {
        return asBinarySerdeType(codec.eventType).fromBinary(payload);
    }
    catch (error) {
        throw createNimiError({
            message: `${methodId} stream event decode failed: ${error instanceof Error ? error.message : String(error)}`,
            reasonCode: ReasonCode.SDK_RUNTIME_STREAM_DECODE_FAILED,
            actionHint: 'check_transport_payload_contract',
            source: 'sdk',
        });
    }
}
//# sourceMappingURL=client-codec.js.map