'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isNameMatch } from '@flint/infra/analysis';
import _0x132a45 from 'pluralize';
import { commonLowerCaseWords } from '../../../base-repo/constants/internal-common-strings.js';
import { typeKeywords } from '../../../base-repo/constants/tools-constants.js';
import { eslintRuleSyntax } from '@flint/infra/constants/eslint-rule-syntax';
import { astNodeAccessors } from '@flint/infra/constants/eslint-syntax-names';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';

var __defProp=Object['defineProperty'],__name=(_0x102359,_0x23feb3)=>__defProp(_0x102359,'name',{'value':_0x23feb3,'configurable':!![]});const ruleName='must-use-plural-enum-const-and-singular-type';const uncountableWords=[commonLowerCaseWords['data'],'equipment','information','news','series','species','software','hardware','money','advice','knowledge',flintRuleIdentifiers['progress'],'traffic','music','education','research','fruit','homework','luggage','weather','work',commonLowerCaseWords['help'],'time','space','shopping'];for(const word of uncountableWords){_0x132a45['addUncountableRule'](word);}const constants={'enumConstPlaceholder':'{{constName}}','messageIds':{'mustUsePluralEnumConstAndSingularType':'mustUsePluralEnumConstAndSingularType'},'meta':{'type':ruleTypes['suggestion'],'docs':{'description':'Enforce\x20plural\x20enum\x20constant\x20names,\x20singular\x20type\x20names,\x20and\x20integer\x20enum\x20values'},'messages':{'mustUsePluralEnumConstAndSingularType':'must-use-plural-enum-const-and-singular-type\x0a{{message}}\x0a\x0a###\x20**Must**\x20use\x20plural\x20enum\x20const\x20and\x20singular\x20type.\x0a\x0a####\x20Wrong\x0a\x0aexport\x20const\x20mode\x20=\x20{\x0a\x20\x20\x20\x20foo:\x20\x22Foo\x22,\x0a\x20\x20\x20\x20bar:\x20\x22Bar\x22,\x0a};\x0aexport\x20type\x20Modes\x20=\x20(typeof\x20mode)[keyof\x20typeof\x20mode];\x0a\x0a####\x20Correct\x0a\x0aexport\x20const\x20modes\x20=\x20{\x0a\x20\x20\x20\x20foo:\x200,\x0a\x20\x20\x20\x20bar:\x201,\x0a};\x0aexport\x20type\x20Mode\x20=\x20(typeof\x20modes)[keyof\x20typeof\x20modes];\x0a\x0a####\x20Why\x0a\x0aWe\x20use\x20singular\x20for\x20type\x20names\x20and\x20plural\x20for\x20constants\x20since\x20singular\x20names\x20are\x20commonly\x20used\x20for\x20property\x20names\x20and\x20parameters.\x20Additionally,\x20we\x20use\x20integer\x20values\x20instead\x20of\x20strings\x20because\x20they\x20are\x20more\x20memory-efficient,\x20provide\x20better\x20type\x20safety,\x20and\x20help\x20prevent\x20errors.'},'schema':[]},'nodeKeys':{'name':commonLowerCaseWords['name'],'expression':astNodeAccessors['embeddedExpression'],'properties':commonLowerCaseWords['properties'],'key':commonLowerCaseWords['key'],'value':commonLowerCaseWords['value']}},createRule=ESLintUtils['RuleCreator'](_0x3afd0b=>''+url+_0x3afd0b),mustUsePluralEnumConstAndSingularType=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x13201f){const _0x5d0f97=[],_0x434c93=[];return {'VariableDeclarator'(_0x5bef83){handleVariableDeclarator(_0x5bef83,_0x5d0f97);},'TSTypeAliasDeclaration'(_0x113116){handleTypeAliasDeclaration(_0x113116,_0x434c93);},[eslintRuleSyntax['programExitSelector']](){handleProgramExit(_0x5d0f97,_0x434c93,_0x13201f);}};}});function getObjectExpression(_0x3e44dd){if(!_0x3e44dd)return void(-0x1140+-0xb19+0x1c59);let _0x2a4236;_0x3e44dd['type']===nodeTypes['objectExpression']&&(_0x2a4236=_0x3e44dd);if(_0x3e44dd['type']===nodeTypes['TSAsExpression']){const _0x381d19=_0x3e44dd[constants['nodeKeys']['expression']];_0x381d19['type']===nodeTypes['objectExpression']&&(_0x2a4236=_0x381d19);}return _0x2a4236;}__name(getObjectExpression,'getObjectExpression');function isTypeAliasKeyofTypeQuery(_0x4cf693){return !!_0x4cf693&&_0x4cf693['type']===nodeTypes['TSTypeOperator']&&_0x4cf693['operator']===typeKeywords['keyof']&&!!_0x4cf693['typeAnnotation']&&_0x4cf693['typeAnnotation']['type']===nodeTypes['TSTypeQuery']&&'exprName'in _0x4cf693['typeAnnotation']&&_0x4cf693['typeAnnotation']['exprName']['type']===nodeTypes['identifier'];}__name(isTypeAliasKeyofTypeQuery,'isTypeAliasKeyofTypeQuery');function isTypeAliasIndexedAccessType(_0x434c91){let _0xf4fe71={'isMatch':![]};if(!_0x434c91||_0x434c91['type']!==nodeTypes['TSIndexedAccessType']||!_0x434c91['objectType']||_0x434c91['objectType']['type']!==nodeTypes['TSTypeQuery']||!_0x434c91['indexType']||_0x434c91['indexType']['type']!==nodeTypes['TSTypeOperator']||_0x434c91['indexType']['operator']!==typeKeywords['keyof'])return _0xf4fe71;const _0x627bac=_0x434c91['objectType'],_0xc0529b=_0x434c91['indexType'];if(_0x627bac['exprName']&&_0x627bac['exprName']['type']===nodeTypes['identifier']&&_0xc0529b['typeAnnotation']&&_0xc0529b['typeAnnotation']['type']===nodeTypes['TSTypeQuery']&&_0xc0529b['typeAnnotation']['exprName']&&_0xc0529b['typeAnnotation']['exprName']['type']===nodeTypes['identifier']){const _0x18ca53=_0x627bac['exprName']['name'],_0x147766=_0xc0529b['typeAnnotation']['exprName']['name'];_0x18ca53===_0x147766&&(_0xf4fe71={'isMatch':!![],'enumName':_0x18ca53});}return _0xf4fe71;}__name(isTypeAliasIndexedAccessType,'isTypeAliasIndexedAccessType');function validateEnumConstName(_0x293479,_0x1f9676){const _0x354403=_0x293479['name'];if(!_0x132a45['isPlural'](_0x354403)&&_0x132a45['isSingular'](_0x354403)){const _0x28e49a='Enum\x20constant\x20\x27{{constName}}\x27\x20should\x20be\x20in\x20plural\x20form.';_0x1f9676['report']({'node':_0x293479,'messageId':constants['messageIds']['mustUsePluralEnumConstAndSingularType'],'data':{'message':_0x28e49a['replace'](constants['enumConstPlaceholder'],_0x354403)}});}}__name(validateEnumConstName,'validateEnumConstName');function validateEnumProperties(_0x35b0b1,_0x50ab70){for(const _0x240490 of _0x35b0b1){if(_0x240490['type']===nodeTypes['property']&&_0x240490['key']['type']===nodeTypes['identifier']){const _0x31b607=_0x240490['value'];if(_0x31b607['type']===nodeTypes['literal']){const _0x26eb2f=_0x31b607['value'];if(typeof _0x26eb2f!=='number'){const _0x1e9560='Enum\x20constant\x20\x27{{key}}\x27\x20should\x20have\x20an\x20integer\x20value\x20instead\x20of\x20\x27{{value}}\x27.',_0xc16756=_0x50ab70['sourceCode']['getText'](_0x240490['key']),_0x2a2f56=String(_0x26eb2f);_0x50ab70['report']({'node':_0x31b607,'messageId':constants['messageIds']['mustUsePluralEnumConstAndSingularType'],'data':{'message':_0x1e9560['replace']('{{key}}',_0xc16756)['replace']('{{value}}',_0x2a2f56)}});}}}}}__name(validateEnumProperties,'validateEnumProperties');function handleVariableDeclarator(_0x351e7e,_0x4750ed){_0x351e7e['id']['type']===nodeTypes['identifier']&&_0x4750ed['push']({'idNode':_0x351e7e['id'],'objectExpr':getObjectExpression(_0x351e7e['init']??void(-0xc3a+0x1*-0x126a+0x1ea4))});}__name(handleVariableDeclarator,'handleVariableDeclarator');function handleTypeAliasDeclaration(_0x6ea234,_0x378e9b){const _0x9f72f5=_0x6ea234['id']['name'];let _0x48cc7a;const _0x59c72b=_0x6ea234['typeAnnotation'];if(isTypeAliasKeyofTypeQuery(_0x59c72b))_0x48cc7a=_0x59c72b['typeAnnotation']['exprName']['name'];else {const _0x5e104b=isTypeAliasIndexedAccessType(_0x59c72b);_0x5e104b['isMatch']&&(_0x48cc7a=_0x5e104b['enumName']);}_0x378e9b['push']({'node':_0x6ea234,'typeName':_0x9f72f5,'enumName':_0x48cc7a});}__name(handleTypeAliasDeclaration,'handleTypeAliasDeclaration');function handleProgramExit(_0x54df2e,_0x2156a0,_0xa8f8f5){for(const _0x110afc of _0x2156a0){if(_0x110afc['enumName']){const _0x490d39=_0x110afc['enumName'],_0x4404c9=_0x54df2e['find'](_0x2eb81f=>isNameMatch(_0x2eb81f['idNode'],_0x490d39)&&_0x2eb81f['objectExpr']),_0x213a4c=_0x4404c9?.['objectExpr'];if(_0x213a4c){validateEnumConstName(_0x4404c9['idNode'],_0xa8f8f5),validateEnumProperties(_0x213a4c['properties'],_0xa8f8f5);const _0x23d1eb=_0x132a45['isPlural'](_0x110afc['typeName'])&&!_0x132a45['isSingular'](_0x110afc['typeName']),_0xc97a38=_0x132a45['plural'](_0x110afc['typeName'])['replace'](/^./,_0x1a0240=>_0x1a0240['toLowerCase']());if(_0x23d1eb||_0xc97a38!==_0x110afc['enumName']){const _0x55da5c='Type\x20alias\x20\x27{{typeName}}\x27\x20should\x20be\x20the\x20singular\x20form\x20of\x20Enum\x20constant\x20\x27{{constName}}\x27.';_0xa8f8f5['report']({'node':_0x110afc['node']['id'],'messageId':constants['messageIds']['mustUsePluralEnumConstAndSingularType'],'data':{'message':_0x55da5c['replace']('{{typeName}}',_0x110afc['typeName'])['replace'](constants['enumConstPlaceholder'],_0x110afc['enumName'])}});}}}}}__name(handleProgramExit,'handleProgramExit');

export { mustUsePluralEnumConstAndSingularType as default, ruleName };
