/*
 * 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 ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-dynamic-slot-context"};ruleDef.prototype.getShortDescription=function(){return"Check properties have valid dynamicSlotDef values"};ruleDef.prototype.getDescription=function(){return"Ensures that any property that defines itself as a dynamic slot discriminant using the dynamicSlotDef attribute is using a valid context defined within the dynamicSlots set for the component"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);const componentType=Utils.getComponentType(meta);if(componentType==="composite"){if(meta.properties){Object.keys(meta.properties).forEach(propName=>{let issueNoticed=false;const prop=meta.properties[propName];if(prop.hasOwnProperty("dynamicSlotDef")){if(meta.dynamicSlots){if(!meta.dynamicSlots.hasOwnProperty(prop.dynamicSlotDef)){issueNoticed=true}}else{issueNoticed=true}}if(issueNoticed){const issue=new context.Issue(`Component ${fullName} property ${propName} references an invalid dynamic-slot`);context.reporter.addIssue(issue,context)}})}}}};module.exports=ruleDef;