/*
 * 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"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;const removeControlMetadata=CaccHelpers.deriveConstraintMetadata(baselines,removeConstraint);if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){if(methodDef.hasOwnProperty("params")){methodDef.params.forEach(paramDef=>{const historicalParamDef=compareMetadata.methods[methodName].params?.find(hpd=>hpd.name===paramDef.name);if(historicalParamDef){const diffs=CaccHelpers.typeDiff(paramDef.type,historicalParamDef.type,overrideTypeMappings);if(CaccHelpers.checkConstraintMinorMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Types ${diffs.add.map(addition=>addition.type).join(", ")} added to method parameter ${methodName}.${paramDef.name} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.mutate,mutateConstraint,componentVersionDiff)){errorConditions.push(`Method parameter type mutated for ${methodName} in${errorMsgContext}'${mutateConstraint}'`)}const removeErrors=CaccHelpers.checkConstraintMajorWithDeprecation(diffs.remove,removeConstraint,componentVersionDiff,cacheManager,componentName,removeControlMetadata,diff=>{return["methods",methodName,"params",`[name:${paramDef.name}]`]},"parameterType",diff=>diff.historicalType);if(removeErrors.length>0){errorConditions.push(`Type(s) ${removeErrors.map(d=>d.historicalType).join(", ")} removed for parameter ${methodName}.${paramDef.name} in${errorMsgContext}'${removeConstraint}'`)}}})}}}}if(errorConditions.length>0){return errorConditions.join("\n")}}return};module.exports=controlCallback;