/*
 * 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-vb-category"};ruleDef.prototype.getShortDescription=function(){return"Verify the category specified "};ruleDef.prototype.getDescription=function(){return"This rule is configured with your preferred Visual Builder component palette category"};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);const componentType=Utils.getComponentType(meta);let category;if(meta.extension&&meta.extension.catalog){category=meta.extension.catalog.category}this._checkCategory(context,fullName,componentType,category)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){let category;if(componentInfo.extension&&componentInfo.extension.catalog){category=componentInfo.extension.catalog.category}this._checkCategory(context,componentInfo.fullName,componentInfo.type,category,true)}};ruleDef.prototype._checkCategory=function(context,fullName,componentType,category,isVComponent){let issue;const allowedCategories=context.rulePack.getRuleCustomOption("categories");if(allowedCategories?.length>0&&Array.isArray(allowedCategories)){switch(componentType){case"composite":case"vbcs-pattern":if(category){if(allowedCategories.filter(cat=>cat===category).length===0){issue=new context.Issue(`Component ${fullName} (${isVComponent?"vcomponent":componentType}) has an unexpected palette category set of '${category}'`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}}else{issue=new context.Issue(`Component ${fullName} (${isVComponent?"vcomponent":componentType}) does not have a palette category set`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}break;default:break}}};module.exports=ruleDef;