'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isUnionOfNumberLiterals, getNumberLiteralValue, isNumberType } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import _0x2de5a4__default from 'typescript';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x415235,_0x2eb142)=>__defProp(_0x415235,'name',{'value':_0x2eb142,'configurable':!![]});const ruleName='no-integers-instead-of-enums';const constants={'messageIds':{'noIntegersInsteadOfEnums':'noIntegersInsteadOfEnums'},'meta':{'type':ruleTypes['problem'],'docs':{'description':'Disallow\x20using\x20integers\x20where\x20a\x20pseudo-enum\x20(union\x20of\x20number\x20literals\x20derived\x20from\x20an\x20object)\x20is\x20expected.'},'messages':{'noIntegersInsteadOfEnums':'no-integers-instead-of-enums\x0aInteger\x20literal\x20\x27{{literalValue}}\x27\x20used\x20where\x20a\x20pseudo-enum\x20(union\x20of\x20number\x20literals)\x20is\x20expected.\x20Use\x20a\x20member\x20of\x20the\x20corresponding\x20object.\x0a\x0a###\x20**Must\x20not**\x20use\x20integers\x20for\x20setting\x20enum\x20values.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20foo:\x20BarStatus\x20=\x200;\x0a\x0a####\x20Correct\x0a\x0aconst\x20foo:\x20BarStatus\x20=\x20barStatuses.baz;\x0a\x0a####\x20Why\x0a\x0aUsing\x20enums\x20instead\x20of\x20numbers\x20provides\x20clarity,\x20type\x20safety,\x20and\x20ease\x20of\x20code\x20maintainability,\x20avoiding\x20ambiguity\x20and\x20errors.'},'schema':[]}},createRule=ESLintUtils['RuleCreator'](_0x12fd85=>''+url+_0x12fd85),noIntegersInsteadOfEnums=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x19595e){const _0x534ac0=_0x19595e['sourceCode']['parserServices'];if(!_0x534ac0?.['program']||!_0x534ac0['esTreeNodeToTSNodeMap'])return {};const _0x5e7e0f={'checker':_0x534ac0['program']['getTypeChecker'](),'tsNodeMap':_0x534ac0['esTreeNodeToTSNodeMap'],'reportedNodes':new Set(),'context':_0x19595e};return {'Literal'(_0x3d5c73){checkExpression(_0x3d5c73,_0x5e7e0f);},'UnaryExpression'(_0x3c81ec){checkExpression(_0x3c81ec,_0x5e7e0f);},'VariableDeclarator'(_0x40b076){checkExpression(_0x40b076['init']??void(0x3*0x351+-0x99e+-0x5*0x11),_0x5e7e0f);},'ReturnStatement'(_0x379a12){checkExpression(_0x379a12['argument']??void(0x7d*0x46+0x2465*0x1+-0x4693),_0x5e7e0f);},'Property'(_0x1b7eea){isExpression(_0x1b7eea['value'])&&checkExpression(_0x1b7eea['value'],_0x5e7e0f);},'ArrayExpression'(_0x323443){for(const _0x277c27 of _0x323443['elements']){_0x277c27&&isExpression(_0x277c27)&&checkExpression(_0x277c27,_0x5e7e0f);}},'AssignmentExpression'(_0x3e7662){checkExpression(_0x3e7662['right'],_0x5e7e0f);}};}});function isExpression(_0x631f9e){const _0x47e55f=_0x631f9e['type'];return _0x47e55f['endsWith']('Expression')||_0x47e55f===nodeTypes['literal']||_0x47e55f===nodeTypes['identifier'];}__name(isExpression,'isExpression');function reportIfNeeded(_0x430afb,_0x507e76,_0x2a22c1,_0x3fa5a3){const _0x3ca87b=first(_0x507e76['range'])+'-'+_0x507e76['range'][-0x431*-0x1+-0x1fbf+-0x19f*-0x11];if(_0x3fa5a3['reportedNodes']['has'](_0x3ca87b)||!_0x2de5a4__default['isExpression'](_0x430afb))return;const _0x321849=_0x3fa5a3['checker']['getContextualType'](_0x430afb),_0x149f48=_0x3fa5a3['checker']['getTypeAtLocation'](_0x430afb);_0x321849&&isUnionOfNumberLiterals(_0x321849)&&(_0x149f48['flags']&_0x2de5a4__default['TypeFlags']['NumberLiteral'])!==-0xc05+0x2362+-0x175d&&(_0x3fa5a3['context']['report']({'node':_0x507e76,'messageId':constants['messageIds']['noIntegersInsteadOfEnums'],'data':{'literalValue':String(_0x2a22c1)}}),_0x3fa5a3['reportedNodes']['add'](_0x3ca87b));}__name(reportIfNeeded,'reportIfNeeded');function checkExpression(_0x503042,_0x3a3a5b){if(!_0x503042||!_0x3a3a5b)return;const _0x1ccf1a=getNumberLiteralValue(_0x503042);if(isNumberType(_0x1ccf1a)){const _0xb56ccf=_0x3a3a5b['tsNodeMap']['get'](_0x503042);_0xb56ccf&&reportIfNeeded(_0xb56ccf,_0x503042,_0x1ccf1a,_0x3a3a5b);}}__name(checkExpression,'checkExpression');

export { noIntegersInsteadOfEnums as default, ruleName };
