"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyMergeStrategy=exports.ArrayMergeStrategy=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var box_1=()=>{var tmp=require("../helpers-internal/box");return box_1=()=>tmp,tmp},deep_merge_1=()=>{var tmp=require("../private/deep-merge");return deep_merge_1=()=>tmp,tmp},token_1=()=>{var tmp=require("../token");return token_1=()=>tmp,tmp};function tryUnbox(value){if(box_1().Box.isBox(value))return value;const reversed=token_1().Tokenization.reverse(value,{failConcat:!1});if(reversed&&box_1().Box.isBox(reversed))return reversed}class ArrayMergeStrategy{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.ArrayMergeStrategy",version:"2.256.1"};static replace(){return new ArrayReplaceStrategy}static append(){return new ArrayAppendStrategy}static prepend(){return new ArrayPrependStrategy}static replaceByIndex(){return new ArrayReplaceByIndexStrategy}static replaceByKey(key){return new BoxSafeArrayStrategy(new ArrayReplaceByKeyStrategy(key))}constructor(){}}exports.ArrayMergeStrategy=ArrayMergeStrategy;class PropertyMergeStrategy{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.PropertyMergeStrategy",version:"2.256.1"};static override(){return new OverrideStrategy}static combine(options){try{jsiiDeprecationWarnings().aws_cdk_lib_CombineStrategyOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.combine),error}return new BoxSafeMergeStrategy(new CombineStrategy(options?.arrays??ArrayMergeStrategy.replace()))}constructor(){}}exports.PropertyMergeStrategy=PropertyMergeStrategy;class CombineStrategy{arrayStrategy;constructor(arrayStrategy){this.arrayStrategy=arrayStrategy}apply(target,source,allowedKeys){for(const key of allowedKeys){if(key==="__proto__"||key==="constructor"||key==="prototype"||!(key in source))continue;const sourceValue=source[key],targetValue=target[key];Array.isArray(sourceValue)&&Array.isArray(targetValue)?target[key]=this.arrayStrategy.merge(targetValue,sourceValue):typeof sourceValue=="object"&&sourceValue!=null&&!Array.isArray(sourceValue)&&typeof targetValue=="object"&&targetValue!=null&&!Array.isArray(targetValue)?target[key]=(0,deep_merge_1().deepMerge)(Object.create(null),targetValue,sourceValue):target[key]=sourceValue}}}class BoxSafeMergeStrategy{delegate;constructor(delegate){this.delegate=delegate}apply(target,source,allowedKeys){for(const key of allowedKeys){if(key==="__proto__"||key==="constructor"||key==="prototype"||!(key in source))continue;const targetValue=target[key],box=tryUnbox(targetValue);if(box){const delegate=this.delegate,sourceValue=source[key];target[key]=box_1().Box.combine({box},({box:resolved})=>{const tmp={value:resolved};return delegate.apply(tmp,{value:sourceValue},["value"]),tmp.value})}else this.delegate.apply(target,source,[key])}}}class OverrideStrategy{apply(target,source,allowedKeys){for(const key of allowedKeys)key==="__proto__"||key==="constructor"||key==="prototype"||key in source&&(target[key]=source[key])}}class BoxSafeArrayStrategy{delegate;constructor(delegate){this.delegate=delegate}merge(target,source){const boxes={};for(let i=0;i<target.length;i++){const box=tryUnbox(target[i]);box&&(boxes[`t${i}`]=box)}if(Object.keys(boxes).length===0)return this.delegate.merge(target,source);const delegate=this.delegate;return box_1().Box.combine(boxes,resolved=>{const resolvedTarget=target.map((el,i)=>`t${i}`in resolved?resolved[`t${i}`]:el);return delegate.merge(resolvedTarget,source)})}}class ArrayReplaceStrategy{merge(_target,source){return source}}class ArrayAppendStrategy{merge(target,source){return[...target,...source]}}class ArrayPrependStrategy{merge(target,source){return[...source,...target]}}class ArrayReplaceByIndexStrategy{merge(target,source){const result=[...target];for(let i=0;i<source.length;i++)result[i]=source[i];return result}}class ArrayReplaceByKeyStrategy{key;constructor(key){this.key=key}merge(target,source){const result=[...target];for(const sourceItem of source){if(typeof sourceItem!="object"||sourceItem==null)continue;const keyValue=sourceItem[this.key],idx=result.findIndex(t=>typeof t=="object"&&t!=null&&t[this.key]===keyValue);idx>=0?result[idx]=sourceItem:result.push(sourceItem)}return result}}
