/*
 * 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 helperPos=require("./helpers/json-propname-pos");const RULE_NAME="oj-cca-compjson-bp-dsplyname";function getName(){return RULE_NAME};function getShortDescription(){return"Best practices for component.json 'displayName'"};function getDescription(){return"Best Practices for component.json metadata require that attribute 'displayName' should be defined for the component, or a property"};function register(regCtx){return{"compjson-composite":_handle,"compjson-pack":_handle}};function _handle(ruleCtx,obj){var o;o=obj&&obj.obj;if(!o){return}_check(ruleCtx,null,o,null,true);_recurseProps(ruleCtx,o)};function _recurseProps(ruleCtx,o,soFar){var propName,prop,propPath;soFar=soFar||"";if(!o.properties){return}for(propName in o.properties){prop=o.properties[propName];propPath=soFar+(soFar?".":"")+propName;_check(ruleCtx,propName,prop,propPath,false);if(prop.properties){_recurseProps(ruleCtx,prop,propPath)}}};function _check(ruleCtx,propName,o,soFar,topLevel){var dsplyName,issue,pos,theProp;dsplyName=o.displayName;if(!dsplyName){if(topLevel){issue=new ruleCtx.Issue("'displayName' should be defined at top level - best practices")}else{issue=new ruleCtx.Issue("'displayName' for property '"+(soFar?soFar:propName)+"' should be defined - best practices");theProp=soFar?soFar:propName;pos=helperPos(ruleCtx,theProp);issue.setPosition(pos.row,pos.col,pos.index,pos.index?pos.index+(theProp.length-1):0)}}else if(typeof dsplyName!=="string"){if(!ruleCtx.rulePack.isRuleEnabled("oj-cca-compjson-prop-types","EXCH")){if(topLevel){issue=new ruleCtx.Issue("'displayName' property is invalid")}else{issue=new ruleCtx.Issue("'displayName' for property '"+(soFar?soFar:propName)+"' is invalid")}issue.setSeverity("blocker");pos=helperPos(ruleCtx,(soFar?soFar+".":"")+(dsplyName?"displayName":propName));issue.setPosition(pos.row,pos.col,pos.index,pos.index?pos.index+9:0)}}if(issue){ruleCtx.reporter.addIssue(issue,ruleCtx)}};module.exports={getName,getDescription,getShortDescription,register};