/*
 * 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"){const errorConditions=[];const{add:addConstraint,remove:removeConstraint}=controlRuleDef;const diffs=bundlesDiff(metadata.bundles,compareMetadata.bundles);if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Bundle(s) ${diffs.add.join(", ")} added to${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`Bundle(s) ${diffs.remove.join(", ")} removed from${errorMsgContext}'${removeConstraint}'`)}if(errorConditions.length>0){return errorConditions.join("\n")}}return};function bundlesDiff(compareBundles,historicalBundles){const compare=compareBundles?compareBundles:{};const historical=historicalBundles?historicalBundles:{};const diffs={add:[],remove:[]};Object.keys(compare).forEach(bundleName=>{if(!historical.hasOwnProperty(bundleName)){diffs.add.push(bundleName)}});Object.keys(historical).forEach(bundleName=>{if(!compare.hasOwnProperty(bundleName)){diffs.remove.push(bundleName)}});return diffs}module.exports=controlCallback;