'use strict';
import { integrationConstants, getIntegrationCache } from '../../meta/server/integration-platforms/fd-integration-cache.js';
import { apiBadRequestError } from '../../../fd-toolbox/server/web/errors.js';
import { getResources } from '../../meta/server/services/resource-provider.js';
import { getUserId } from '../../meta/server/auth/users/current-user-id-provider.js';
import { getResourceNameFromResourceMetaId } from '../../meta/server/services/resource-name-converter.js';
import { subscriptionEventStrings, subscriptionEventTypes } from '../../meta/server/integration-platforms/integration-events.js';
import { isSubscriptionEvent, subscriptionEventsOData } from '../integration-platforms/subscription-odata.js';
import { apiNoContentResponse, apiOkResponse } from '../../meta/server/web/responses.js';
import { crudPost, crudPut } from '../../meta/server/controllers/generic-controllers/crud-controller.js';
import { responseMessages } from '../../../fd-toolbox/server/web/response-messages.js';

var __defProp=Object['defineProperty'],__name=(_0x5c1a41,_0x3cde60)=>__defProp(_0x5c1a41,'name',{'value':_0x3cde60,'configurable':!![]});async function integrationGetRoute(_0x589c0b){const _0x3e0c28=new URL(_0x589c0b['url'])['searchParams']['get'](integrationConstants['resourceMetaId']),_0x482eb3=new URL(_0x589c0b['url'])['searchParams']['get'](integrationConstants['event']);if(!_0x3e0c28||!_0x482eb3)throw apiBadRequestError();const _0xc15b14=await getResourceNameFromResourceMetaId(_0x3e0c28),_0x1eddfb=await getUserId();let _0x12e084;if(isSubscriptionEvent(_0x482eb3)){let _0x42cba1;(_0x482eb3===subscriptionEventStrings[subscriptionEventTypes['resourceAdded']]||_0x482eb3===subscriptionEventStrings[subscriptionEventTypes['resourceEdited']])&&(_0x42cba1=await getResources(_0xc15b14,_0x1eddfb,subscriptionEventsOData[_0x482eb3]));_0x482eb3===subscriptionEventStrings[subscriptionEventTypes['resourceRemoved']]&&(_0x42cba1=await getIntegrationCache(subscriptionEventStrings[subscriptionEventTypes['resourceRemoved']],_0x3e0c28));if(!_0x42cba1)return apiNoContentResponse();_0x12e084=apiOkResponse(_0x42cba1);}else throw apiBadRequestError();return _0x12e084;}__name(integrationGetRoute,'integrationGetRoute');async function integrationPostRoute(_0x4e6de1){const _0x3515af=new URL(_0x4e6de1['url'])['searchParams']['get'](integrationConstants['resourceMetaId']);if(!_0x3515af)throw apiBadRequestError();const _0x3e6689=await getResourceNameFromResourceMetaId(_0x3515af);if(_0x3e6689)return crudPost(_0x4e6de1,_0x3e6689);else throw apiBadRequestError(responseMessages['routingError']);}__name(integrationPostRoute,'integrationPostRoute');async function integrationPutRoute(_0x2a4b1e){const _0x7e68a0=new URL(_0x2a4b1e['url'])['searchParams']['get'](integrationConstants['resourceMetaId']);if(!_0x7e68a0)throw apiBadRequestError();const _0x132ac7=await getResourceNameFromResourceMetaId(_0x7e68a0);if(_0x132ac7)return crudPut(_0x2a4b1e,_0x132ac7);else throw apiBadRequestError(responseMessages['routingError']);}__name(integrationPutRoute,'integrationPutRoute');

export { integrationGetRoute, integrationPostRoute, integrationPutRoute };
