'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { isIdentifier, isExplicitlyTypedVariable, getDefinition } from '@flint/infra/analysis';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x3a26c2,_0x13134e)=>__defProp(_0x3a26c2,'name',{'value':_0x13134e,'configurable':!![]});const ruleName='must-always-specify-types-for-api-responses';const ruleContent='\x0a###\x20**Must**\x20always\x20specify\x20types\x20for\x20api\x20responses\x0a\x0a####\x20Wrong\x0a\x0aexport\x20function\x20GET()\x20{\x0a\x20\x20\x20\x20const\x20context\x20=\x20getContext();\x0a\x20\x20\x20\x20const\x20result\x20=\x20getResult();\x0a\x0a\x20\x20\x20\x20return\x20apiOkResponse({\x20context,\x20result\x20});\x0a}\x0a\x0a####\x20Correct\x0a\x0aexport\x20function\x20GET()\x20{\x0a\x20\x20\x20\x20const\x20context\x20=\x20getContext();\x0a\x20\x20\x20\x20const\x20result\x20=\x20getResult();\x0a\x0a\x20\x20\x20\x20const\x20response:\x20FooType\x20=\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20context:\x20context,\x0a\x20\x20\x20\x20\x20\x20\x20\x20result:\x20result,\x0a\x20\x20\x20\x20};\x0a\x0a\x20\x20\x20\x20return\x20apiOkResponse(response);\x0a}\x0a\x0a####\x20Why\x0a\x0aAdds\x20an\x20additional\x20level\x20of\x20type\x20checking\x20to\x20prevent\x20further\x20errors\x20and\x20type\x20inconsistencies.\x20It\x20also\x20helps\x20with\x20refactoring\x20code,\x20as\x20you\x20can\x20search\x20by\x20the\x20type\x20name\x20directly.\x0a';var mustAlwaysSpecifyTypesForApiResponses = createEslintRule(ruleName,ruleContent,_0x499f4d=>{return {'CallExpression'(_0x5916c2){if(!isApiResponseCall(_0x5916c2))return;const _0x259600=firstOrUndefined(_0x5916c2['arguments']);_0x259600&&(!isIdentifier(_0x259600)||!isExplicitlyTypedVariable(getDefinition(_0x259600,_0x499f4d['sourceCode'])))&&_0x499f4d['report']({'node':_0x259600,'messageId':ruleName});}};});function isApiResponseCall(_0x392d66){const _0x5db138=/^((api(.*)Response)|getJsonResponse)$/;return isIdentifier(_0x392d66['callee'])&&_0x5db138['test'](_0x392d66['callee']['name']);}__name(isApiResponseCall,'isApiResponseCall');

export { mustAlwaysSpecifyTypesForApiResponses as default, ruleName };
