/*
 * 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-property-changed"};ruleDef.prototype.getShortDescription=function(){return"Checks for the existence of a propertyChanged function"};ruleDef.prototype.getDescription=function(){return"This rule ensures that any component that has properties also provides a propertyChanged lifecycle listener to handle async updates to those properties"};ruleDef.prototype.register=function(context){return{FunctionExpression:Utils.setupFileMethodMapping.bind(Utils),ArrowFunctionExpression:Utils.setupFileMethodMapping.bind(Utils),MethodDefinition:Utils.setupFileMethodMappingFromMethodDefintion.bind(Utils),CallExpression:Utils.deriveViewModels.bind(Utils),closedownRP:this._doAudit}};ruleDef.prototype._doAudit=function(context){let issue;if(context.rulePack.getExtension()){context.rulePack.getExtension().allComponents.forEach(compInfo=>{if(compInfo.viewModel&&compInfo.viewModel.resolved){if(!Utils.shouldIgnoreCheck(context,"jetwc-property-changed",compInfo.fullName)){if(compInfo.properties){const vmMethods=Utils.getVMMethodsForLocalComposite(context,compInfo);if(vmMethods&&!vmMethods.has("propertyChanged")){let reportSource=compInfo.fullName;if(compInfo.viewModel.resolved&&!compInfo.viewModel.skip){reportSource=compInfo.viewModel.path}issue=new context.Issue(`Component '${compInfo.fullName}' supports properties but does not provide a 'propertyChanged()' lifecycle method to react to async changes to those properties`);issue.setReportedFilePath(reportSource);context.reporter.addIssue(issue,context)}}}}})}};module.exports=ruleDef;