'use strict';
import { nodeTypes, findPropertyInObject, getVariableInScope } from '@flint/infra/analysis';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { eslintRuleSyntax } from '@flint/infra/constants/eslint-rule-syntax';

var __defProp=Object['defineProperty'],__name=(_0x5b0251,_0x5c6a43)=>__defProp(_0x5b0251,'name',{'value':_0x5c6a43,'configurable':!![]});const ruleName='must-use-constants-for-message-ids';const ruleContent='\x0a###\x20**Must**\x20use\x20ruleName\x20constant.\x0a\x0aYou\x20must\x20reference\x20the\x20messageId\x20directly\x20through\x20the\x20`ruleName`\x20constant.\x20Literals,\x20objects,\x20or\x20variables\x20are\x20not\x20allowed.\x0a\x0a####\x20Wrong\x0a\x0acontext.report({\x20messageId:\x20\x22foo\x22\x20});\x0acontext.report({\x20messageId:\x20bar\x20});\x0acontext.report({\x20messageId:\x20foo.bar\x20});\x0acontext.report({\x20messageId:\x20constants.messageIds.foo\x20});\x0a\x0a####\x20Correct\x0a\x0acontext.report({\x20messageId:\x20ruleName\x20});\x0a\x0a####\x20Why\x0a\x0aUsing\x20constants\x20ensures\x20type\x20safety,\x20prevents\x20typos,\x20and\x20makes\x20refactoring\x20easier.\x20It\x20also\x20enforces\x20a\x20single\x20source\x20of\x20truth\x20for\x20message\x20ID.',constants={'ruleNameIdentifier':eslintRuleSyntax['ruleName'],'contextIdentifier':'context','reportMethod':eslintRuleSyntax['report'],'messageIdProperty':eslintRuleSyntax['messageId'],'variableDefinitionType':nodeTypes['variable']};var mustUseConstantsForMessageIds = createEslintRule(ruleName,ruleContent,_0x59d747=>{return {'CallExpression'(_0x1a4bb5){if(isContextReportCall(_0x1a4bb5,_0x59d747['sourceCode']))for(const _0x481aca of _0x1a4bb5['arguments']){const _0x20fc60=getPropertiesFromArgument(_0x481aca,_0x59d747['sourceCode']);if(_0x20fc60){const _0x135f93=findPropertyInObject(_0x20fc60,constants['messageIdProperty']);if(_0x135f93){!isValidConstantsUsage(_0x135f93['value'])&&_0x59d747['report']({'node':_0x135f93['value'],'messageId':ruleName});break;}}}}};});function isDirectContextReportCall(_0x2f8cad){return _0x2f8cad['type']===nodeTypes['memberExpression']&&_0x2f8cad['object']['type']===nodeTypes['identifier']&&_0x2f8cad['object']['name']===constants['contextIdentifier']&&_0x2f8cad['property']['type']===nodeTypes['identifier']&&_0x2f8cad['property']['name']===constants['reportMethod'];}__name(isDirectContextReportCall,'isDirectContextReportCall');function isAliasedReportCall(_0x14acd3,_0x4ed7fc){if(_0x14acd3['callee']['type']!==nodeTypes['identifier']||_0x14acd3['callee']['name']!==constants['reportMethod'])return ![];const _0x2bcd5a=getVariableInScope(_0x4ed7fc,_0x14acd3,constants['reportMethod'])?.['defs']?.['at'](-0x1*-0x163c+0x27*-0x16+0x2*-0x971);return Boolean(_0x2bcd5a&&_0x2bcd5a['type']===constants['variableDefinitionType']&&_0x2bcd5a['node']['type']===nodeTypes['variableDeclarator']&&_0x2bcd5a['node']['init']&&_0x2bcd5a['node']['init']['type']===nodeTypes['identifier']&&_0x2bcd5a['node']['init']['name']===constants['contextIdentifier']);}__name(isAliasedReportCall,'isAliasedReportCall');function isContextReportCall(_0x12f259,_0x1d9cfd){return isDirectContextReportCall(_0x12f259['callee'])||isAliasedReportCall(_0x12f259,_0x1d9cfd);}__name(isContextReportCall,'isContextReportCall');function isValidConstantsUsage(_0x5c1bd0){return _0x5c1bd0['type']===nodeTypes['identifier']&&_0x5c1bd0['name']===constants['ruleNameIdentifier'];}__name(isValidConstantsUsage,'isValidConstantsUsage');function resolveObjectExpression(_0x1f50dc,_0x24cd3e){const _0x3d9168=getVariableInScope(_0x24cd3e,_0x1f50dc,_0x1f50dc['name'])?.['defs']?.['at'](0x16e5+-0x6ff+-0xb9*0x16);let _0x27b241;return _0x3d9168&&_0x3d9168['type']===constants['variableDefinitionType']&&_0x3d9168['node']['init']&&_0x3d9168['node']['init']['type']===nodeTypes['objectExpression']&&(_0x27b241=_0x3d9168['node']['init']),_0x27b241;}__name(resolveObjectExpression,'resolveObjectExpression');function getPropertiesFromArgument(_0x2e3cef,_0x2007b0){let _0x1b53e6;if(_0x2e3cef['type']===nodeTypes['objectExpression'])_0x1b53e6=_0x2e3cef['properties'];else {if(_0x2e3cef['type']===nodeTypes['identifier']){const _0x23011d=resolveObjectExpression(_0x2e3cef,_0x2007b0);_0x23011d&&(_0x1b53e6=_0x23011d['properties']);}}return _0x1b53e6;}__name(getPropertiesFromArgument,'getPropertiesFromArgument');

export { mustUseConstantsForMessageIds as default, ruleName };
