'use strict';
import { ODataBuilder } from '../../../fd-toolbox/odata/odata-builders.js';
import { oAuthProviderProps } from '../../common/resources/props/oauth-service-props.js';
import { withUserIdProps } from '../../../fd-toolbox/types/with-user-id.js';
import { getUserId } from '../../meta/server/auth/users/current-user-id-provider.js';
import { getResources } from '../../meta/server/services/resource-provider.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { toolboxUserConstants } from '../../meta/constants/toolbox-users.js';
import { oDataComparisonTypes } from '../../../fd-toolbox/odata/odata-enums.js';
import { oDataOperators } from '../../../fd-toolbox/enums/enums.js';
import { getWorkerBotCrudUpdateConfig } from '../../meta/server/meta-core/crud/crud-update-config.js';
import { crudUpdate } from '../../meta/server/basic-crud/cruds.js';
import { isNumber } from '../../../fd-toolbox/types/ensure-type.js';
import { getCurrentDateAddSeconds } from '../../../fd-toolbox/time/date-time.js';
import { singleOrUndefinedWithWarning } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x2c6f1c,_0x9838a0)=>__defProp(_0x2c6f1c,'name',{'value':_0x9838a0,'configurable':!![]});async function getOAuthProviderByCurrentUser(_0x1067f9){const _0x105f1e=new ODataBuilder();_0x105f1e['filter'](oAuthProviderProps['authType'],_0x1067f9,oDataOperators['equal'],{'comparisonType':oDataComparisonTypes['equal']})['filter'](withUserIdProps['userId'],await getUserId(),oDataOperators['equal'],{'comparisonType':oDataComparisonTypes['equal']});const _0x382db7=singleOrUndefinedWithWarning(await getResources(resourceNames['oAuthProvider'],toolboxUserConstants['workerBotId'],_0x105f1e['build'](),![]));if(!_0x382db7)return void(0x2c5*0xd+-0xd83+-0x167e);return _0x382db7;}__name(getOAuthProviderByCurrentUser,'getOAuthProviderByCurrentUser');async function getOAuthProviderByAuthKey(_0x3544bd,_0x35a85e){const _0x499e9b=new ODataBuilder();_0x499e9b['filter'](oAuthProviderProps['authType'],_0x3544bd,oDataOperators['equal'],{'comparisonType':oDataComparisonTypes['equal']})['filter'](oAuthProviderProps['authKey'],_0x35a85e,oDataOperators['equal'],{'comparisonType':oDataComparisonTypes['equal']});const _0x33f530=singleOrUndefinedWithWarning(await getResources(resourceNames['oAuthProvider'],toolboxUserConstants['workerBotId'],_0x499e9b['build'](),![]));if(!_0x33f530)return void(-0x602*0x4+-0x16b6+-0x1*-0x2ebe);return _0x33f530;}__name(getOAuthProviderByAuthKey,'getOAuthProviderByAuthKey');async function updateOAuthProviderToken(_0x45db43,_0x39f4ef){const _0x18f7d9=isNumber(_0x39f4ef['accessTokenExpireTime'])?getCurrentDateAddSeconds(_0x39f4ef['accessTokenExpireTime']):_0x39f4ef['accessTokenExpireTime'],_0x4c3ec9={..._0x45db43,'accessApiToken':_0x39f4ef['accessToken'],'accessApiTokenExpiresAt':_0x18f7d9};if(_0x39f4ef['refreshToken'])_0x4c3ec9['refreshApiToken']=_0x39f4ef['refreshToken'];await crudUpdate(getWorkerBotCrudUpdateConfig(_0x4c3ec9,resourceNames['oAuthProvider']));}__name(updateOAuthProviderToken,'updateOAuthProviderToken');

export { getOAuthProviderByAuthKey, getOAuthProviderByCurrentUser, updateOAuthProviderToken };
