import { must } from "../../../shared/src/must.js";
import { decodeSecProtocols, } from "../../../zero-protocol/src/connect.js";
import { URLParams } from "../types/url-params.js";
export function getConnectParams(protocolVersion, url, headers) {
    const params = new URLParams(url);
    try {
        const clientID = params.get('clientID', true);
        const clientGroupID = params.get('clientGroupID', true);
        const schemaVersion = params.getInteger('schemaVersion', false);
        const baseCookie = params.get('baseCookie', false);
        const timestamp = params.getInteger('ts', true);
        const lmID = params.getInteger('lmid', true);
        const wsID = params.get('wsid', false) ?? '';
        const userID = params.get('userID', false) ?? '';
        const debugPerf = params.getBoolean('debugPerf');
        const { initConnectionMessage, authToken } = decodeSecProtocols(must(headers['sec-websocket-protocol']));
        return {
            params: {
                protocolVersion,
                clientID,
                clientGroupID,
                schemaVersion,
                baseCookie,
                timestamp,
                lmID,
                wsID,
                debugPerf,
                initConnectionMsg: initConnectionMessage,
                auth: authToken,
                userID,
                httpCookie: headers.cookie,
            },
            error: null,
        };
    }
    catch (e) {
        return {
            params: null,
            error: e instanceof Error ? e.message : String(e),
        };
    }
}
//# sourceMappingURL=connect-params.js.map