/*
 * 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 VC=require("./jetwco-cacc-auditConstraints");const CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;if(metadata.hasOwnProperty("events")&&compareMetadata.hasOwnProperty("events")){for(const[eventName,eventDef]of Object.entries(metadata.events)){if(compareMetadata.events.hasOwnProperty(eventName)){const diffs=CaccHelpers.apiDiff(eventDef.detail,compareMetadata.events[eventName].detail);if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Detail attribute(s) ${diffs.add.map(addition=>addition.name).join(", ")} added to ${eventName} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`Detail attribute(s) ${diffs.remove.map(removal=>removal.name).join(", ")} removed from ${eventName} in ${errorMsgContext}'${removeConstraint}'`)}if(diffs.mutate.length>0){diffs.mutate.forEach(mutation=>{const mdType=eventDef.detail[mutation.name].type;const historicalType=compareMetadata.events[eventName].detail[mutation.name].type;if(mdType!==historicalType){if(mutateConstraint===VC.NEVER||componentVersionDiff<4){errorConditions.push(`Detail attribute type change for ${mutation.name} in ${eventName} in${errorMsgContext}'${mutateConstraint}'`)}}})}}}}if(errorConditions.length>0){return errorConditions.join("\n")}}return};module.exports=controlCallback;