'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { fileExtensions } from '../../../base-repo/app-constants/internal-system-constants.js';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { commonLowerCaseWords, collectionMethodNames, fileBaseNames } from '../../../base-repo/constants/internal-common-strings.js';
import { fileSuffixes } from '../../../base-repo/constants/internal-extensions.js';
import { runtimeConstructors } from '../../../base-repo/constants/runtime-constants.js';
import { getFileName, isIdentifier, isPascalCase, isFunctionExpression, isExportNamedVariableDeclaration, isDeclarationExportedAsDefault, hasJSXReturn, isExportNamedDeclaration, isExportDefaultDeclaration, nodeTypes } from '@flint/infra/analysis';
import { eslintRuleSyntax } from '@flint/infra/constants/eslint-rule-syntax';
import _0x1869d0__default from 'path';
import _0x132a45 from 'pluralize';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { arrayTypeSyntax, runtimeStaticMethods } from '@flint/infra/constants/runtime-constants';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x3a9284,_0x48c092)=>__defProp(_0x3a9284,'name',{'value':_0x48c092,'configurable':!![]});const ruleName='must-use-plural-names-of-files-for-arrays';const ruleContent='\x0aFile\x20name\x20\x27{{fileName}}\x27\x20should\x20be\x20plural\x20\x27{{suggestedName}}\x27\x20because\x20it\x20contains\x20exported\x20collections.\x0a\x0a###\x20**Must**\x20use\x20plural\x20names\x20of\x20files\x20if\x20the\x20file\x20contains\x20set\x20of\x20objects,\x20arrays\x20or\x20work\x20with\x20collections\x0a\x0a####\x20Wrong\x0a\x0a//\x20user.ts\x0aexport\x20const\x20users\x20=\x20[{\x20id:\x201,\x20name:\x20\x22Alice\x22\x20},\x20{\x20id:\x202,\x20name:\x20\x22Bob\x22\x20}];\x0a\x0a####\x20Correct\x0a\x0a//\x20users.ts\x20\x0aexport\x20const\x20users\x20=\x20[{\x20id:\x201,\x20name:\x20\x22Alice\x22\x20},\x20{\x20id:\x202,\x20name:\x20\x22Bob\x22\x20}];\x0a\x0a####\x20Why\x0a\x0aThis\x20naming\x20convention\x20improves\x20code\x20clarity,\x20ensures\x20consistency\x20across\x20the\x20project,\x20and\x20aligns\x20with\x20RESTful\x20principles\x20by\x20distinguishing\x20between\x20individual\x20entities\x20and\x20collections.',constants={'collections':{'set':runtimeConstructors['set'],'map':runtimeConstructors['map'],'array':runtimeConstructors['array']},'defaultIgnorePatterns':Array['from'](['*.test.*','*'+fileSuffixes['dotSpecDot']+'*',fileBaseNames['index']+'.*','*'+fileSuffixes['config']+'*','*'+fileExtensions['dts'],'setup.*','submodules-config.*']),'collectionKinds':{'array':jsBasicTypes['array'],'map':collectionMethodNames['map'],'set':commonLowerCaseWords['set'],'typedArray':arrayTypeSyntax['typedArray']}};var mustUsePluralNamesOfFilesForArrays = createEslintRule(ruleName,ruleContent,__name(function create(_0x36c6d8){const _0x2c8408=firstOrUndefined(_0x36c6d8['options'])?.['ignorePatterns']??constants['defaultIgnorePatterns'],_0x41bbcf=[];let _0x1ffb3b=![];return {'FunctionDeclaration'(_0x56f5e8){_0x56f5e8['id']&&isPascalCase(_0x56f5e8['id']['name'])&&(isExportNamedDeclaration(_0x56f5e8['parent'])||isExportDefaultDeclaration(_0x56f5e8['parent'])||isDeclarationExportedAsDefault(_0x56f5e8,_0x36c6d8['sourceCode']))&&hasJSXReturn(_0x56f5e8)&&(_0x1ffb3b=!![]);},'VariableDeclarator'(_0x20b495){const _0x40ffc1=isCollectionType(_0x20b495,_0x36c6d8);_0x40ffc1&&_0x41bbcf['push'](_0x40ffc1),isIdentifier(_0x20b495['id'])&&isPascalCase(_0x20b495['id']['name'])&&_0x20b495['init']&&isFunctionExpression(_0x20b495['init'])&&(isExportNamedVariableDeclaration(_0x20b495['parent']?.['parent'])||isDeclarationExportedAsDefault(_0x20b495,_0x36c6d8['sourceCode']))&&hasJSXReturn(_0x20b495['init'])&&(_0x1ffb3b=!![]);},[eslintRuleSyntax['programExitSelector']](){if(_0x41bbcf['length']===0x21c6+0x6ff+0x28c5*-0x1)return;const _0x22e6e5=getFileName(_0x36c6d8['filename']);if(shouldIgnoreFile(_0x22e6e5,_0x2c8408))return;const _0x230b93=_0x1869d0__default['extname'](_0x22e6e5);if(_0x230b93===fileExtensions['tsx']&&_0x1ffb3b)return;const _0x433163=getFileName(_0x22e6e5,_0x230b93),_0x39cd80=firstOrUndefined(_0x41bbcf);!_0x132a45['isPlural'](_0x433163)&&_0x41bbcf['length']>-0x2*-0x720+-0xcd1+-0x16f*0x1&&_0x39cd80&&reportViolation(_0x36c6d8,_0x39cd80['node'],_0x433163,_0x230b93);}};},'create'),{'schema':[{'type':'object','properties':{'ignorePatterns':{'type':jsBasicTypes['array'],'items':{'type':'string'},'default':constants['defaultIgnorePatterns']}},'additionalProperties':![]}],'defaultOptions':[{'ignorePatterns':Array['from'](constants['defaultIgnorePatterns'])}]});function shouldIgnoreFile(_0x2e453a,_0x211e94){return _0x211e94['some'](_0x15dc60=>{const _0x124897=_0x15dc60['replace'](/\./g,'\x5c.')['replace'](/\*/g,'.*');return new RegExp('^'+_0x124897+'$')['test'](_0x2e453a);});}__name(shouldIgnoreFile,'shouldIgnoreFile');function isCollectionType(_0xb780f1,_0x1166a5){const _0x2a472a=_0xb780f1['init'],_0x1492b8=_0xb780f1['id'];if(!_0x2a472a||_0x1492b8['type']!==nodeTypes['identifier'])return void(0x1*0xa2d+-0x11*0x13a+0xaad);if(!isExportNamedVariableDeclaration(_0xb780f1['parent']?.['parent']))return void(-0x9ae+0x176d*0x1+-0xdbf);const _0x420d82=_0x1492b8['name'],_0xa5fb40=checkArrayExpression(_0x2a472a,_0x420d82,_0xb780f1)??checkNewExpression(_0x2a472a,_0x420d82,_0xb780f1)??checkArrayFromCall(_0x2a472a,_0x420d82,_0xb780f1);if(_0xa5fb40)return _0xa5fb40;return checkCollectionTypeWithTypeScript(_0xb780f1,_0x1166a5,_0x420d82);}__name(isCollectionType,'isCollectionType');function checkCollectionTypeWithTypeScript(_0x391917,_0x57ce15,_0x9435b1){try{const _0x44b993=ESLintUtils['getParserServices'](_0x57ce15);if(!_0x44b993['program']||!_0x44b993['esTreeNodeToTSNodeMap'])return void(-0x1*0x10d2+0x1202*0x1+0x10*-0x13);const _0x8fe57a=_0x44b993['program']['getTypeChecker'](),_0xa83ecf=_0x44b993['esTreeNodeToTSNodeMap']['get'](_0x391917);if(!_0xa83ecf?.['name'])return void(-0x157*-0xe+0x1e49+-0x310b);const _0x2755cd=_0x8fe57a['getSymbolAtLocation'](_0xa83ecf['name']);if(!_0x2755cd?.['valueDeclaration'])return void(0x1323+-0x316+-0x1*0x100d);const _0x396a64=_0x8fe57a['getTypeOfSymbolAtLocation'](_0x2755cd,_0x2755cd['valueDeclaration']),_0x30626f=_0x8fe57a['typeToString'](_0x396a64);return checkTypedArrayType(_0x30626f,_0x9435b1,_0x391917)??checkSetType(_0x30626f,_0x9435b1,_0x391917)??checkMapType(_0x30626f,_0x9435b1,_0x391917);}catch{return void(-0x1d56+-0x5c3+0xbb3*0x3);}}__name(checkCollectionTypeWithTypeScript,'checkCollectionTypeWithTypeScript');function checkTypedArrayType(_0x144055,_0x460d61,_0x1d3be4){if(_0x144055['includes']('[]')||_0x144055['startsWith'](arrayTypeSyntax['generic'])){let _0x38659={'name':_0x460d61,'type':constants['collectionKinds']['typedArray'],'node':_0x1d3be4};return _0x38659;}return void(0x2*0x529+0x3a9*-0x9+0x169f);}__name(checkTypedArrayType,'checkTypedArrayType');function checkSetType(_0x4490d1,_0x1ff449,_0xa83548){if(_0x4490d1['startsWith']('Set<')){let _0x3a53e2={'name':_0x1ff449,'type':constants['collectionKinds']['set'],'node':_0xa83548};return _0x3a53e2;}return void(-0x93f+-0xbb4+0x1*0x14f3);}__name(checkSetType,'checkSetType');function checkMapType(_0x564e42,_0x1ef047,_0x3a146f){if(_0x564e42['startsWith']('Map<')){let _0x3196cb={'name':_0x1ef047,'type':constants['collectionKinds']['map'],'node':_0x3a146f};return _0x3196cb;}return void(0x1b*0xa2+0x1d3+-0x12e9);}__name(checkMapType,'checkMapType');function checkArrayExpression(_0x3112be,_0x2f5063,_0x146762){if(_0x3112be['type']===nodeTypes['arrayExpression']){let _0x3e9f41={'name':_0x2f5063,'type':constants['collectionKinds']['array'],'node':_0x146762};return _0x3e9f41;}return void(-0xd9a+0x215b*-0x1+0x2ef5);}__name(checkArrayExpression,'checkArrayExpression');function checkNewExpression(_0x203326,_0x25a156,_0x3b1b67){if(_0x203326['type']===nodeTypes['newExpression']&&_0x203326['callee']['type']===nodeTypes['identifier']){let _0x34c0ee;return _0x203326['callee']['name']===constants['collections']['set']&&(_0x34c0ee={'name':_0x25a156,'type':constants['collectionKinds']['set'],'node':_0x3b1b67}),_0x203326['callee']['name']===constants['collections']['map']&&(_0x34c0ee={'name':_0x25a156,'type':constants['collectionKinds']['map'],'node':_0x3b1b67}),_0x203326['callee']['name']===constants['collections']['array']&&(_0x34c0ee={'name':_0x25a156,'type':constants['collectionKinds']['array'],'node':_0x3b1b67}),_0x34c0ee;}return void(0x15f1*0x1+0x9f2+-0x1fe3);}__name(checkNewExpression,'checkNewExpression');function checkArrayFromCall(_0x38c8d7,_0x2ff0d0,_0x54f986){if(_0x38c8d7['type']===nodeTypes['callExpression']&&_0x38c8d7['callee']['type']===nodeTypes['memberExpression']&&_0x38c8d7['callee']['object']['type']===nodeTypes['identifier']&&_0x38c8d7['callee']['object']['name']===runtimeConstructors['array']&&_0x38c8d7['callee']['property']['type']===nodeTypes['identifier']&&_0x38c8d7['callee']['property']['name']===runtimeStaticMethods['from']){let _0x5d658e={'name':_0x2ff0d0,'type':constants['collectionKinds']['typedArray'],'node':_0x54f986};return _0x5d658e;}return void(0x22a5+-0x1953*0x1+-0x1*0x952);}__name(checkArrayFromCall,'checkArrayFromCall');function generateSuggestedFileName(_0xcdfe3e,_0x4f4730){const _0x4cabf5=_0x132a45['plural'](_0xcdfe3e);return ''+_0x4cabf5+_0x4f4730;}__name(generateSuggestedFileName,'generateSuggestedFileName');function reportViolation(_0xc0be6d,_0x6ff41d,_0x31bd92,_0x2a5cdd){const _0x52451d=generateSuggestedFileName(_0x31bd92,_0x2a5cdd),_0x429271=''+_0x31bd92+_0x2a5cdd;_0xc0be6d['report']({'node':_0x6ff41d,'messageId':ruleName,'data':{'fileName':_0x429271,'suggestedName':_0x52451d}});}__name(reportViolation,'reportViolation');

export { mustUsePluralNamesOfFilesForArrays as default, ruleName };
