'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { isIdentifier, isMemberExpression, nodeTypes } from '@flint/infra/analysis';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { eslintProperties } from '@flint/infra/constants/rules-meta';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x1a5e7a,_0x1808a7)=>__defProp(_0x1a5e7a,'name',{'value':_0x1808a7,'configurable':!![]});const ruleName='no-manual-resource-instantiation';const ruleContent='\x0a###\x20**Must\x20not**\x20use\x20new\x20keyword\x20with\x20resources.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20foo\x20=\x20new\x20FooResource();\x0a\x0a####\x20Correct\x0a\x0aconst\x20bar:\x20FooResource\x20=\x20{\x20...\x20};\x0a\x0a####\x20Why\x0a\x0aResources\x20use\x20classes,\x20but\x20under\x20the\x20hood\x20they\x20are\x20not\x20classes,\x20they\x20are\x20plain\x20objects.';var noManualResourceInstantiation = createEslintRule(ruleName,ruleContent,__name(function create(_0x1ee1fb,_0x2acaf8){const _0x3f76d1=first(_0x2acaf8)['restrictedClasses'];return {'NewExpression'(_0x2fc2b3){let _0x4a3678,_0xb52323;const _0x3fd0f6=_0x2fc2b3['callee'];if(isIdentifier(_0x3fd0f6))_0x4a3678=_0x3fd0f6['name'];else isMemberExpression(_0x3fd0f6)&&isIdentifier(_0x3fd0f6['object'])&&isIdentifier(_0x3fd0f6['property'])&&(_0x4a3678=_0x3fd0f6['object']['name'],_0xb52323=_0x3fd0f6['property']['name']);if(_0x4a3678!==void(-0x485+-0xc5*-0x3+0x236)){const _0xfeccee=_0x1ee1fb['sourceCode']['getScope'](_0x2fc2b3),_0x2ec9bb=resolveVariable(_0x4a3678,_0xfeccee);if(_0x2ec9bb===void(-0x2*-0x5c9+-0x776+-0x41c)){const _0x22b99c=_0xb52323??_0x4a3678,_0x58e912=findRestriction(_0x3f76d1,_0x22b99c);_0x58e912!==void(0x25d7+0x1a6a+-0x156b*0x3)&&_0x1ee1fb['report']({'node':_0x2fc2b3,'messageId':ruleName});}else checkVariableDefinitions(_0x2ec9bb,_0x4a3678,_0x2fc2b3,_0x1ee1fb,_0x3f76d1,_0xb52323);}}};},'create'),{'schema':[{'type':'object','properties':{'restrictedClasses':{'type':jsBasicTypes['array'],'items':{'type':jsBasicTypes['object'],'properties':{'name':{'type':jsBasicTypes['string']},'fromPath':{'type':jsBasicTypes['string']}},'required':[eslintProperties['name']],'additionalProperties':![]}}},'additionalProperties':![]}],'defaultOptions':[{'restrictedClasses':[]}]});function checkVariableDefinitions(_0x2e2d44,_0x3ad71f,_0x1cf7a2,_0x1a4763,_0x16f38c,_0x18d07a){for(const _0x549568 of _0x2e2d44['defs']){if(_0x549568['type']===nodeTypes['importBinding']){const _0x34e43b=_0x549568['parent'];if(_0x34e43b['type']===nodeTypes['importDeclaration']){const _0x27508a=getImportedOriginalName(_0x549568,_0x18d07a)??_0x18d07a??_0x3ad71f,_0xdaeaf5=_0x34e43b['source']['value'],_0x5cba2d=findRestriction(_0x16f38c,_0x27508a,_0xdaeaf5);if(_0x5cba2d!==void(0xa62*-0x2+-0x23*-0x9f+-0x3*0x53)){_0x1a4763['report']({'node':_0x1cf7a2,'messageId':ruleName});break;}}}}}__name(checkVariableDefinitions,'checkVariableDefinitions');function getImportedOriginalName(_0x15e289,_0x5c24d9){let _0x323a33;const _0x4d8c9b=_0x15e289['node'];if(_0x4d8c9b['type']===nodeTypes['importSpecifier']&&isIdentifier(_0x4d8c9b['imported']))_0x323a33=_0x4d8c9b['imported']['name'];else _0x4d8c9b['type']===nodeTypes['importNamespaceSpecifier']&&_0x5c24d9!==void(-0x1cb7+0xce9*-0x2+0x3689)&&(_0x323a33=_0x5c24d9);return _0x323a33;}__name(getImportedOriginalName,'getImportedOriginalName');function resolveVariable(_0x1af5bf,_0x3c2afb){let _0x32c6d6,_0x36ce61=_0x3c2afb;while(_0x36ce61){const _0x30cb5c=_0x36ce61['set']['get'](_0x1af5bf);_0x30cb5c!==void(-0x3*-0xb5d+0x1997+-0x2*0x1dd7)?(_0x32c6d6=_0x30cb5c,_0x36ce61=void(0x1cd4+-0x2452*-0x1+-0x4126)):_0x36ce61=_0x36ce61['upper']??void(-0x1*-0x174e+-0x4*-0x19a+-0x1db6);}return _0x32c6d6;}__name(resolveVariable,'resolveVariable');function findRestriction(_0x5825d2,_0x2ccc63,_0x4915db){return _0x5825d2['find'](_0x5e90db=>{let _0x45547a=_0x5e90db['name']===_0x2ccc63;return _0x45547a&&_0x5e90db['fromPath']!==void(-0x1a*-0x74+-0x1cf1+-0xbf*-0x17)&&(_0x45547a=_0x4915db!==void(-0x736+0x109*-0x6+0xd6c)&&new RegExp(_0x5e90db['fromPath'])['test'](_0x4915db)),_0x45547a;});}__name(findRestriction,'findRestriction');

export { noManualResourceInstantiation as default, ruleName };
