/*
 * 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==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){const diffs=CaccHelpers.typeDiff(methodDef.return,compareMetadata.methods[methodName].return,overrideTypeMappings);if(diffs.mutate.length>0){let refactorMutate=false;diffs.mutate.forEach(({type,historicalType})=>{if(type.length>0&&historicalType.length===0){diffs.add.push({type});refactorMutate=true}if(historicalType.length>0&&type.length===0){diffs.remove.push(historicalType);refactorMutate=true}});if(refactorMutate){diffs.mutate=[]}}if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Method return type amended to include ${diffs.add.map(addition=>addition.type).join(", ")} added to ${methodName} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.mutate,mutateConstraint,componentVersionDiff)){const errorAction=diffs.mutate[0].type?"added":"removed";errorConditions.push(`Method return type ${errorAction} for ${methodName} in${errorMsgContext}'${mutateConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`Method return type removed for ${methodName} in${errorMsgContext}'${removeConstraint}'`)}}}if(errorConditions.length>0){return errorConditions.join("\n")}}}return};module.exports=controlCallback;