/*
 * 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 helperProp=require("../../rules/jet/helpers/bp-checkPropType");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-compjson-bp-obj"};ruleDef.prototype.getShortDescription=function(){return"Web component component.json metadata should follow best practices and avoid 'object' type properties"};ruleDef.prototype.getDescription=function(){return"For best practices, web components should avoid use of the property type 'object' without sub-properties, and provide a more complete definition of the API either using sub-properties or using a closure type definition"};ruleDef.prototype.register=function(context){if(context.rulePack.isRuleEnabled("oj-cca-compjson-bp-obj","JET")){return false}else{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);if(componentType==="composite"){this._checkProps(context,fullName,meta.properties)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkProps(context,componentInfo.fullName,componentInfo.properties)}};ruleDef.prototype._checkProps=function(context,fullName,properties){if(properties){const objectProps=helperProp(properties,"o");if(objectProps){for(let i=0;i<objectProps.length;i++){const checkProperty=objectProps[i];if(!this._hasSub_properties(properties,checkProperty)){if(!Utils.shouldIgnoreCheck(context,"jetwc-compjson-bp-obj",fullName,"properties",checkProperty)){const issue=new context.Issue(`property '${checkProperty}' of type 'object' has no sub-properties. Provide a more complete API definition using sub-properties or a closure type definition`);context.reporter.addIssue(issue,context)}}}}}};ruleDef.prototype._hasSub_properties=function(props,prop){var subprop,a,i;if(!prop.includes(".")){return!!props[prop].properties}a=prop.split(".");for(i=0;i<a.length;i++){subprop=props[a[i]];if(subprop&&subprop.properties){if(a.length-1===i){return true}props=subprop.properties;continue}break}return false};module.exports=ruleDef;