'use strict';
import { folders } from '../../../base-repo/app-constants/project-paths.js';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { hasCallGenericType, hasGenericTypeAssertion, hasGenericTypeInEnclosingParameters, hasGenericTypeInVariableDeclarator, hasGenericTypeInTypeNode, hasGenericTypeInCallableDefinitionReturn } from '@flint/infra/analysis/generic-analysis';
import { getVariableDefinitionsInScope } from '@flint/infra/analysis/type-analysis';
import { isIdentifier, isMemberExpression, isSpreadElement, isCallExpression, isVariableDeclarator } from '@flint/infra/analysis';
import { isNameMatch } from '@flint/infra/analysis/name-analysis';
import { flintRuleActionNames } from '@flint/infra/constants/rule-strings';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x5328b2,_0x1762db)=>__defProp(_0x5328b2,'name',{'value':_0x1762db,'configurable':!![]});const ruleName='must-use-typed-resources-for-crud-update';const ruleContent='\x0a###\x20**Must**\x20have\x20generic\x20type\x20for\x20Crud\x20Update\x20or\x20config.\x0a\x0a####\x20Wrong\x0a\x0aawait\x20crudUpdate(...);\x0a\x0aconst\x20config\x20=\x20{...};\x0aawait\x20crudUpdate(config);\x0a\x0a####\x20Correct\x0a\x0aawait\x20crudUpdate<Foo>();\x0a\x0aconst\x20config:\x20Config<Foo>\x20=\x20{...};\x0aawait\x20crudUpdate(config);\x0a\x0a####\x20Why\x0a\x0aIt\x20prevents\x20typization\x20errors.';var mustUseTypedResourcesForCrudUpdate = createEslintRule(ruleName,ruleContent,_0x3fe166=>{return {'CallExpression'(_0x4a4171){if(!isCrudUpdateCall(_0x4a4171))return;if(hasCallGenericType(_0x4a4171['typeArguments']))return;if(hasTypedConfigArgument(_0x4a4171,_0x3fe166['sourceCode']))return;_0x3fe166['report']({'node':_0x4a4171,'messageId':ruleName});}};});function isCrudUpdateCall(_0x1ed68d){let _0x5bb28c=![];return isIdentifier(_0x1ed68d['callee'])&&(_0x5bb28c=isNameMatch(_0x1ed68d['callee'],flintRuleActionNames['crudUpdate'])),!_0x5bb28c&&isMemberExpression(_0x1ed68d['callee'])&&(_0x5bb28c=isIdentifier(_0x1ed68d['callee']['object'])&&isNameMatch(_0x1ed68d['callee']['object'],folders['api'])&&!_0x1ed68d['callee']['computed']&&isIdentifier(_0x1ed68d['callee']['property'])&&isNameMatch(_0x1ed68d['callee']['property'],flintRuleActionNames['crudUpdate'])),_0x5bb28c;}__name(isCrudUpdateCall,'isCrudUpdateCall');function hasTypedConfigArgument(_0x2659f7,_0x5d0271){const _0x2423bf=firstOrUndefined(_0x2659f7['arguments']);let _0x175594=![];if(_0x2423bf&&!isSpreadElement(_0x2423bf)){if(isIdentifier(_0x2423bf))_0x175594=hasGenericTypeInDefinition(_0x2423bf,_0x2659f7,_0x5d0271);else isCallExpression(_0x2423bf)?_0x175594=hasTypedConfigInCallArgument(_0x2423bf,_0x2659f7,_0x5d0271):_0x175594=hasGenericTypeAssertion(_0x2423bf);}return _0x175594;}__name(hasTypedConfigArgument,'hasTypedConfigArgument');function hasGenericTypeInDefinition(_0x1d53a6,_0x491fbb,_0x4c7cbb){let _0x2aa24b=![];const _0x551abf=getVariableDefinitionsInScope(_0x4c7cbb,_0x491fbb,_0x1d53a6['name']);return _0x551abf['length']>0x1fbe+0x34e+0x4*-0x8c3&&(_0x2aa24b=_0x551abf['some'](_0xac1afd=>hasGenericTypeInVariableDefinition(_0xac1afd,_0x1d53a6['name']))),!_0x2aa24b&&(_0x2aa24b=hasGenericTypeInEnclosingParameters(_0x1d53a6['name'],_0x491fbb['parent'],{'stopAtNearestFunction':!![]})),Boolean(_0x2aa24b);}__name(hasGenericTypeInDefinition,'hasGenericTypeInDefinition');function hasGenericTypeInVariableDefinition(_0x40c465,_0xdd80c7){const _0x2cab3b=_0x40c465['node'];let _0x47d30e=![];return isVariableDeclarator(_0x2cab3b)&&(_0x47d30e=hasGenericTypeInVariableDeclarator(_0x2cab3b)),!_0x47d30e&&(isIdentifier(_0x40c465['name'])&&_0x40c465['name']['name']===_0xdd80c7&&(_0x47d30e=hasGenericTypeInTypeNode(_0x40c465['name']['typeAnnotation']?.['typeAnnotation']))),_0x47d30e;}__name(hasGenericTypeInVariableDefinition,'hasGenericTypeInVariableDefinition');function hasTypedConfigInCallArgument(_0x32002d,_0x4fb563,_0x70a54b){let _0x5b18e6=hasCallGenericType(_0x32002d['typeArguments']);return !_0x5b18e6&&(_0x5b18e6=hasGenericTypeInCalledFunctionReturn(_0x32002d,_0x4fb563,_0x70a54b)),_0x5b18e6;}__name(hasTypedConfigInCallArgument,'hasTypedConfigInCallArgument');function hasGenericTypeInCalledFunctionReturn(_0x2e248f,_0x451a1f,_0x1134ff){let _0x1aca7b=![];if(isIdentifier(_0x2e248f['callee'])){const _0x24b67c=getVariableDefinitionsInScope(_0x1134ff,_0x451a1f,_0x2e248f['callee']['name']);_0x1aca7b=_0x24b67c['some'](hasGenericTypeInCallableDefinitionReturn);}return _0x1aca7b;}__name(hasGenericTypeInCalledFunctionReturn,'hasGenericTypeInCalledFunctionReturn');

export { mustUseTypedResourcesForCrudUpdate as default, ruleName };
