/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-jet-version"};ruleDef.prototype.getShortDescription=function(){return"Verify the JET version range of a component "};ruleDef.prototype.getDescription=function(){return"This rule is configured with your required JET version range for a set of components to make sure that they are all consistent"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);if(meta.jetVersion&&fullName){this._checkVersion(context,fullName,meta.jetVersion)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo&&componentInfo.jetVersion){this._checkVersion(context,componentInfo.fullName,componentInfo.jetVersion)}};ruleDef.prototype._checkVersion=function(context,fullName,version){let issue;const ruleOptions=context.rulePack.getRuleCustomOptions();let targetJetVersion;if(ruleOptions.hasOwnProperty("jetVersion")){targetJetVersion=ruleOptions.jetVersion}else{targetJetVersion=context.utils.jafLib.getConfig().getJetVer()}if(ruleOptions.hasOwnProperty("versionMatch")){switch(ruleOptions.versionMatch){case"absolute":if(targetJetVersion!==version){issue=new context.Issue(`Component ${fullName} does not support the expected JET version range ${targetJetVersion} (found ${version})`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}break;case"upperLimit":if(!context.utils.semVerUtils.satisfiesRange(targetJetVersion,version)){issue=new context.Issue(`Component ${fullName} does not support the required version of JET ${targetJetVersion} (supported range found ${version})`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}break}}};module.exports=ruleDef;