/*
 * 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 CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="pack"&&metadata.bundles){const{add:addConstraint,remove:removeConstraint}=controlRuleDef;const errorConditions=[];for(const[bundleName,bundleContents]of Object.entries(metadata.bundles)){const historicalBundleContents=compareMetadata.hasOwnProperty("bundles")&&compareMetadata.bundles.hasOwnProperty(bundleName)?compareMetadata.bundles[bundleName]:[];const diffs=CaccHelpers.stringArrayDiff(bundleContents,historicalBundleContents);if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Entries ${diffs.add.join(", ")} added to bundle ${bundleName} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`Entries ${diffs.remove.join(", ")} removed from ${bundleName} in${errorMsgContext}'${removeConstraint}'`)}}if(errorConditions.length>0){return errorConditions.join("\n")}}return};module.exports=controlCallback;