/*
 * 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 path=require("path");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-public-modules"};ruleDef.prototype.getShortDescription=function(){return"Ensure the publicModules definition in a resource component is valid"};ruleDef.prototype.getDescription=function(){return"This rule checks that any classes listed in publicModules are correctly specified and exist"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);const componentType=Utils.getComponentType(meta);const componentRoot=path.dirname(context.filepath);if(componentType==="resource"&&meta.publicModules){meta.publicModules.forEach(modulePath=>{let checkPath=Utils.toJAFPath(path.join(componentRoot,modulePath));if(path.extname(modulePath)!==""){issue=new context.Issue(`Resource component ${fullName} publicModule references should not include file extension`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}else{if(!context.utils.fsUtils.fileExistsSync(checkPath+".js")){if(!context.utils.fsUtils.fileExistsSync(checkPath+".ts")&&!context.utils.fsUtils.fileExistsSync(checkPath+".tsx")){issue=new context.Issue(`Resource component ${fullName} publicModule reference '${modulePath}' does not exist as a JS, TS or TSX file`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}}}})}}};module.exports=ruleDef;