'use strict';
import { oDataQueryParams } from '../../../../../fd-toolbox/constants/odata-query-params.js';
import { oDataDataTypePrefixes, oDataSeparators, oDataLogicalOperators, oDataRegexPatterns, oDataSpecialValues, oDataComparisonOperators, oDataLambdaOperators } from '../../../../../fd-toolbox/odata/odata-filter-constants.js';
import { tsBasicTypes } from '../../../../../base-repo/constants/basic-types.js';
import { oDataOrderByDirections, oDataOperators } from '../../../../../fd-toolbox/enums/enums.js';
import { oDataLogicalOperationTypes, oDataFilterTypes, oDataComparisonTypes } from '../../../../../fd-toolbox/odata/odata-enums.js';
import { createError } from '../../../../../fd-toolbox/errors/errors.js';
import { convertFromPascalToCamelCase, isPascalCase } from '../../../../../fd-toolbox/strings/casing-converter.js';
import { toolboxErrorMessages } from '../../../../../fd-toolbox/constants/toolbox-error-messages-constants.js';
import { oDataLambdaMethods } from '../../../../../fd-toolbox/odata/odata-lambda-method.js';
import { trimQuotesRegex, removeNonAlphanumericEndRegex, uuidRegex, numericRegex, guidPrefixWithParenthesisLength, guidPrefixLength, parenthesizedContent } from '../../../../../fd-toolbox/constants/odata-constants.js';
import { first } from '../../../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x39d41f,_0x888fb8)=>__defProp(_0x39d41f,'name',{'value':_0x888fb8,'configurable':!![]});const parenthesizedGuidPrefix='('+oDataDataTypePrefixes['guidPrefix'];function prepareODataSelectOrExpandTree(_0x5e030d){const _0x1bf12c=_0x5e030d??[],_0x5672f0={};return _0x1bf12c['forEach'](_0x7aa0e0=>{const _0x4a847b=_0x7aa0e0['split'](oDataSeparators['propertySeparator']);let _0x139a48=_0x5672f0;_0x4a847b['forEach'](_0x426aa6=>{_0x139a48['children']??={},!_0x139a48['children'][_0x426aa6]&&(_0x139a48['children'][_0x426aa6]={}),_0x139a48=_0x139a48['children'][_0x426aa6];});}),_0x5672f0;}__name(prepareODataSelectOrExpandTree,'prepareODataSelectOrExpandTree');function parseODataFilter(_0x1cc8c8){const _0xe3043b=[];if(!_0x1cc8c8['trim']())return _0xe3043b;let _0x2b907c=![];const _0x565976=metaSplitFilters(_0x1cc8c8);for(const _0x73adaf of _0x565976){if(_0x73adaf===oDataLogicalOperators['or'])_0x2b907c=!![];else {const _0x14cceb={'logicalOperationType':oDataLogicalOperationTypes['and'],'comparisonType':getComparisonType(_0x73adaf)};_0x2b907c&&(_0x14cceb['logicalOperationType']=oDataLogicalOperationTypes['or'],_0x2b907c=![]);const _0x20eb24=setLambdaConfigAndGetFilterComponents(_0x73adaf,_0x14cceb);_0x14cceb['leftSide']=convertFromPascalToCamelCase(first(_0x20eb24));if(_0x20eb24[0xc6a*0x3+0x1*-0x2513+-0x3*0xe]['startsWith'](parenthesizedGuidPrefix)||_0x20eb24[0x9dd*-0x1+0x94*-0x12+-0x3*-0x6c2]['startsWith'](oDataDataTypePrefixes['guidPrefix'])){const _0x3d05d6=parseGuidFilterValue(_0x20eb24[0x2*-0xaf7+0x1807*-0x1+-0xf52*-0x3]);_0x14cceb['rightSide']=trimWithRegex(_0x3d05d6,![],oDataSeparators['stringQuote']),_0x14cceb['type']=oDataFilterTypes['guid'];}else {if(_0x20eb24[0xb*-0x1be+-0x67*-0x2f+0x42]['startsWith'](oDataDataTypePrefixes['datePrefix']))_0x14cceb['rightSide']=trimWithRegex(_0x20eb24[-0x25*0x107+-0x1414+-0x1a*-0x23c]['substring'](-0x23d3+-0xaa2+0x16*0x21d),![],oDataSeparators['stringQuote'],oDataSeparators['timezoneSuffix']);else {const _0x1520e1=trimWithRegex(_0x20eb24[0x1132*-0x2+0x16e5+-0x8*-0x170],!![],oDataSeparators['stringQuote'],oDataSeparators['openParenthesis']);_0x14cceb['rightSide']=trimWithRegex(_0x1520e1,![],oDataSeparators['stringQuote'],oDataSeparators['closeParenthesis']);}}_0xe3043b['push'](_0x14cceb);}}return _0xe3043b;}__name(parseODataFilter,'parseODataFilter');function parseExpand(_0x131b10){if(!_0x131b10)return [];return _0x131b10['split'](oDataSeparators['selectSeparator']);}__name(parseExpand,'parseExpand');function parseSorts(_0x54c8b8){if(_0x54c8b8){const _0x2a7cd5=[],_0x3818d0=_0x54c8b8['split'](oDataSeparators['selectSeparator']);for(const _0x499ec3 of _0x3818d0){const _0x4a28bb=_0x499ec3['trim']()['split'](oDataSeparators['space']),_0x4af9bc=first(_0x4a28bb),_0x14da83={'propertyName':isPascalCase(_0x4af9bc)?convertFromPascalToCamelCase(_0x4af9bc):_0x4af9bc,'priority':0x0,'direction':_0x4a28bb[-0x1bd9+-0x21a*-0xb+0x4*0x12f]===oDataQueryParams['orderByDesc']?oDataOrderByDirections['desc']:oDataOrderByDirections['asc']};_0x2a7cd5['push'](_0x14da83);}return _0x2a7cd5;}return [];}__name(parseSorts,'parseSorts');function parseSelects(_0x2fec7){return _0x2fec7['split'](oDataSeparators['selectSeparator']);}__name(parseSelects,'parseSelects');function trimWithRegex(_0x1b0536,_0x4b04ba,..._0x30cd40){const _0x381113=_0x30cd40['map'](escapeChar),_0x4610ab='['+_0x381113['join'](oDataSeparators['emptyString'])+']+',_0x31030a=_0x4b04ba?oDataSeparators['emptyString']:oDataRegexPatterns['endOfLineMarker'],_0x72386f=new RegExp(''+_0x4610ab+_0x31030a);return _0x1b0536['replace'](_0x72386f,oDataSeparators['emptyString']);}__name(trimWithRegex,'trimWithRegex');function metaSplitFilters(_0x495d5a){return _0x495d5a['split'](new RegExp('\x5cs*('+oDataLogicalOperators['or']+'|'+oDataLogicalOperators['and']+')\x5cs*',oDataRegexPatterns['caseInsensitiveFlag']))['filter'](_0x22713c=>_0x22713c['trim']()!==oDataSeparators['emptyString']&&_0x22713c!==oDataLogicalOperators['and']);}__name(metaSplitFilters,'metaSplitFilters');function parseRightSideToArray(_0x57ad74){const _0x260e64=[],_0x54805d=_0x57ad74['trim']()['replace'](trimQuotesRegex,oDataSpecialValues['parameterPlaceholder'])['split'](oDataSeparators['selectSeparator']);for(const _0x417539 of _0x54805d){let _0x54ee61=_0x417539['replaceAll'](oDataSeparators['stringQuote'],oDataSeparators['emptyString'])['trim']();_0x54ee61=_0x54ee61['replace'](removeNonAlphanumericEndRegex,oDataSeparators['emptyString'])['trim']();if(uuidRegex['test'](_0x54ee61))_0x260e64['push'](_0x54ee61);else _0x54ee61['includes'](oDataDataTypePrefixes['guidPrefix'])?_0x260e64['push'](_0x54ee61['replace'](oDataDataTypePrefixes['guidPrefix'],oDataSeparators['emptyString'])['trim']()):_0x260e64['push'](numericRegex['test'](_0x54ee61)?String(parseInt(_0x54ee61,-0x2308+0xded+-0x1525*-0x1)):_0x54ee61);}return _0x260e64;}__name(parseRightSideToArray,'parseRightSideToArray');function getComparisonType(_0x45c9b7){for(const [_0x3fe426,_0x1485a1]of filterConstantToComparison){if(_0x45c9b7['includes'](_0x3fe426))return _0x1485a1;}throw createError(toolboxErrorMessages['unpredictableExpression']);}__name(getComparisonType,'getComparisonType');const filterConstantToComparison=new Map([[oDataComparisonOperators['eq'],oDataComparisonTypes['equal']],[oDataComparisonOperators['ne'],oDataComparisonTypes['notEqual']],[oDataComparisonOperators['gt'],oDataComparisonTypes['greaterThan']],[oDataComparisonOperators['ge'],oDataComparisonTypes['greaterThanOrEqual']],[oDataComparisonOperators['lt'],oDataComparisonTypes['lessThan']],[oDataComparisonOperators['le'],oDataComparisonTypes['lessThanOrEqual']],[oDataComparisonOperators['in'],oDataComparisonTypes['in']],[oDataComparisonOperators['nin'],oDataComparisonTypes['nin']],[oDataOperators['startsWith'],oDataComparisonTypes['startsWith']]]);function setLambdaConfigAndGetFilterComponents(_0x37f497,_0x3da5a9){if(_0x37f497['includes'](oDataSeparators['propertySeparator']+tsBasicTypes['any']+oDataSeparators['openParenthesis'])){const _0x1870cf=setODataLambdaConfigAndGetFilterString(_0x3da5a9,_0x37f497,oDataLambdaMethods['any']);return getSplittedWithConstantsFilter(_0x1870cf);}else {if(_0x37f497['includes'](oDataSeparators['propertySeparator']+oDataLambdaOperators['all']+oDataSeparators['openParenthesis'])){const _0x4e3372=setODataLambdaConfigAndGetFilterString(_0x3da5a9,_0x37f497,oDataLambdaMethods['all']);return getSplittedWithConstantsFilter(_0x4e3372);}else {if(_0x37f497['includes'](oDataOperators['startsWith']+oDataSeparators['openParenthesis'])){const _0x2d1fc4=oDataRegexPatterns['functionParametersPattern'],_0x907505=_0x2d1fc4['exec'](_0x37f497);return [_0x907505?.[0x16df*-0x1+-0x1*0x87d+0x1f*0x103]??oDataSeparators['emptyString'],_0x907505?.[0x1a02+-0x1ef7+-0x29*-0x1f]??oDataSeparators['emptyString']];}}}return getSplittedWithConstantsFilter(_0x37f497);}__name(setLambdaConfigAndGetFilterComponents,'setLambdaConfigAndGetFilterComponents');function setODataLambdaConfigAndGetFilterString(_0xc22552,_0x4fdbd1,_0xb288b7){_0xc22552['type']=oDataFilterTypes['lambda'];const _0x57862d=_0x4fdbd1['split'](oDataSeparators['propertySeparator'],0x22ee+-0xafd+-0xbf7*0x2),_0x17e02d={'baseEnumerablePropertyName':first(_0x57862d),'method':_0xb288b7};return _0xc22552['lambdaConfig']=_0x17e02d,trimWithRegex(_0x57862d[_0x57862d['length']-(-0x10a*-0x8+-0x9df+0x190)],![],oDataSeparators['closeParenthesis']);}__name(setODataLambdaConfigAndGetFilterString,'setODataLambdaConfigAndGetFilterString');function getSplittedWithConstantsFilter(_0x439b15){return _0x439b15['split'](new RegExp(oDataComparisonOperators['eq']+'|'+oDataComparisonOperators['ne']+'|'+oDataComparisonOperators['gt']+'|'+oDataComparisonOperators['ge']+'|'+oDataComparisonOperators['lt']+'|'+oDataComparisonOperators['le']+'|'+oDataComparisonOperators['in']+'|'+oDataComparisonOperators['nin']+'|'+oDataOperators['startsWith']));}__name(getSplittedWithConstantsFilter,'getSplittedWithConstantsFilter');function parseGuidFilterValue(_0xedc125){const _0x2270fd=[],_0x11a247=_0xedc125['split'](oDataSeparators['selectSeparator']);for(const _0x438562 of _0x11a247){let _0x42e572=_0x438562['startsWith'](parenthesizedGuidPrefix)?_0x438562['substring'](guidPrefixWithParenthesisLength):_0x438562['substring'](guidPrefixLength);_0x42e572=_0x42e572['replace'](trimQuotesRegex,oDataSpecialValues['parameterPlaceholder']),_0x42e572=_0x42e572['replace'](parenthesizedContent,oDataSpecialValues['parameterPlaceholder']),_0x42e572=_0x42e572['replace'](removeNonAlphanumericEndRegex,oDataSeparators['emptyString'])['trim'](),_0x2270fd['push'](_0x42e572);}return _0x2270fd['join'](oDataSeparators['selectSeparator']);}__name(parseGuidFilterValue,'parseGuidFilterValue');function escapeChar(_0x5ad3f5){let _0x3a70db=_0x5ad3f5;if(_0x5ad3f5==='(')_0x3a70db=String['raw']`\(`;else _0x5ad3f5===')'&&(_0x3a70db=String['raw']`\)`);return _0x3a70db;}__name(escapeChar,'escapeChar');

export { metaSplitFilters, parseExpand, parseODataFilter, parseRightSideToArray, parseSelects, parseSorts, prepareODataSelectOrExpandTree, trimWithRegex };
