/*
 * 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 CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;const removeControlMetadata=CaccHelpers.deriveConstraintMetadata(baselines,removeConstraint);return recurseThroughProps(controlRuleName,componentName,metadata,compareMetadata,removeControlMetadata,["properties"],addConstraint,removeConstraint,componentVersionDiff,cacheManager,errorMsgContext).join("\n")}return};function recurseThroughProps(controlRuleName,componentName,metadata,compareMetadata,removeControlMetadata,compareScope,addConstraint,removeConstraint,componentVersionDiff,cacheManager,errorMsgContext){let errorConditions=[];const printScope=CaccHelpers.getPrintScope(compareScope);const diffs=CaccHelpers.apiDiff(CaccHelpers.castToScope(metadata,compareScope),CaccHelpers.castToScope(compareMetadata,compareScope));if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Properties ${printScope}${diffs.add.map(prop=>prop.name).join(", ")} added to${errorMsgContext}'${addConstraint}'`)}const cleanedRemoveDiffs=diffs.remove.filter(prop=>{return!_isExemptedGlobalProperty(prop.name)});const removeErrors=CaccHelpers.checkConstraintMajorWithDeprecation(cleanedRemoveDiffs,removeConstraint,componentVersionDiff,cacheManager,componentName,removeControlMetadata,diff=>{return compareScope.concat([diff.name])});if(removeErrors.length>0){errorConditions.push(`Properties ${printScope}${cleanedRemoveDiffs.map(prop=>prop.name).join(", ")} removed from${errorMsgContext}'${removeConstraint}'`)}if(diffs.mutate.length>0){diffs.mutate.forEach(mutation=>{let newScope=compareScope.slice().concat([mutation.name,"properties"]);const mutateErrors=recurseThroughProps(controlRuleName,componentName,metadata,compareMetadata,removeControlMetadata,newScope,addConstraint,removeConstraint,componentVersionDiff,cacheManager,errorMsgContext);if(mutateErrors){errorConditions=errorConditions.concat(mutateErrors)}})}return errorConditions}function _isExemptedGlobalProperty(propertyName){return["autofocus","autoFocus"].includes(propertyName)}module.exports=controlCallback;