'use strict';
import { workspaceConstants } from '../../../../fd-toolbox/server/constants/workspace-constants.js';
import { getSessionToken, getCurrentWorkspaceIdFromSession, getSessionFromCache } from '../auth/session-access.js';
import { isTest } from '../../../../fd-toolbox/lib/environments.js';

var __defProp=Object['defineProperty'],__name=(_0x2f3725,_0x165b40)=>__defProp(_0x2f3725,'name',{'value':_0x165b40,'configurable':!![]});const defaultWorkspaceId=workspaceConstants['defaultWorkspaceId'];let processWorkspaceId=new Map();async function getCurrentWorkspaceId(){let _0xf942ae,_0x3f6e56;const _0x262470=processWorkspaceId['get'](process['pid']);if(isTest()&&_0x262470!==void(0x5dc+0x1abd+0x2099*-0x1))return _0x262470;try{_0xf942ae=await getSessionToken();}catch{return _0x3f6e56=_0x262470??defaultWorkspaceId,_0x3f6e56;}if(!_0xf942ae)_0x3f6e56=defaultWorkspaceId;else {const _0x3a2f1a=await getCurrentWorkspaceIdFromSession(_0xf942ae);!_0x3a2f1a?_0x3f6e56=defaultWorkspaceId:(setCurrentWorkspaceId(_0x3a2f1a),_0x3f6e56=_0x3a2f1a);}return _0x3f6e56;}__name(getCurrentWorkspaceId,'getCurrentWorkspaceId');async function getCurrentWorkspaceIdFromCache(){let _0x4c5bba,_0x380db7;const _0x1afb40=processWorkspaceId['get'](process['pid']);if(isTest()&&_0x1afb40!==void(-0x1209+0x2+0x1207))return _0x1afb40;try{_0x4c5bba=await getSessionToken();}catch{_0x4c5bba=void(-0xffb+0x5*0x5ba+-0xca7);}if(!_0x4c5bba)_0x380db7=defaultWorkspaceId;else try{const _0x13a3f7=await getSessionFromCache(_0x4c5bba),_0xdecedc=_0x13a3f7?.['currentWorkspaceId']??await getCurrentWorkspaceIdFromSession(_0x4c5bba);_0xdecedc&&setCurrentWorkspaceId(_0xdecedc),_0x380db7=_0xdecedc??defaultWorkspaceId;}catch{_0x380db7=defaultWorkspaceId;}return _0x380db7;}__name(getCurrentWorkspaceIdFromCache,'getCurrentWorkspaceIdFromCache');function setCurrentWorkspaceId(_0x4ad014){processWorkspaceId['set'](process['pid'],_0x4ad014);}__name(setCurrentWorkspaceId,'setCurrentWorkspaceId');function resetCurrentWorkspaceId(){processWorkspaceId['set'](process['pid'],void(0x2432+-0x738+0x2*-0xe7d));}__name(resetCurrentWorkspaceId,'resetCurrentWorkspaceId');

export { getCurrentWorkspaceId, getCurrentWorkspaceIdFromCache, resetCurrentWorkspaceId, setCurrentWorkspaceId };
