/*
 * Copyright (c) 2018, 2025, 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 ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-packable-components"};ruleDef.prototype.getShortDescription=function(){return"Validate that components that are, or are not, defined as part of a pack"};ruleDef.prototype.getDescription=function(){return"This rule checks the type of a component and detects, in the case that it is part of a pack, if this should be the case (or not)"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit}};ruleDef.prototype._doAudit=function(context){const componentMetadata=context.suppData.obj;if(componentMetadata){let issue;const componentType=Utils.getComponentType(componentMetadata);const componentPack=componentMetadata.pack;switch(componentType){case"pack":case"reference":case"vbcs-template":if(componentPack){issue=new context.Issue(`Component '${componentMetadata.name}' (type: ${componentType}), should be defined as a singleton component, not as a member of a pack`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}break;case"resource":if(!componentPack){issue=new context.Issue(`Component '${componentMetadata.name}' (type: ${componentType}), should be defined as a member of a pack, not a singleton`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}break;case"demo":if(componentPack){issue=new context.Issue(`Component '${componentMetadata.name}', we advise that demo components are not included in a pack`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context,"minor")}break}}};module.exports=ruleDef;