"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.TagType=exports.CfnResource=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),cxapi=require("../../cx-api"),cfn_element_1=require("./cfn-element"),cfn_resource_policy_1=require("./cfn-resource-policy"),constructs_1=require("constructs"),deps_1=require("./deps"),cfn_reference_1=require("./private/cfn-reference"),cloudformation_lang_1=require("./private/cloudformation-lang"),removal_policy_1=require("./removal-policy"),tag_manager_1=require("./tag-manager"),token_1=require("./token"),util_1=require("./util");class CfnResource extends cfn_element_1.CfnRefElement{constructor(scope,id,props){super(scope,id);if(this.cfnOptions={},this.rawOverrides={},this.dependsOn=new Set,jsiiDeprecationWarnings.aws_cdk_lib_CfnResourceProps(props),!props.type)throw new Error("The `type` property is required");this.cfnResourceType=props.type,this._cfnProperties=props.properties||{},constructs_1.Node.of(this).tryGetContext(cxapi.PATH_METADATA_ENABLE_CONTEXT)&&this.addMetadata(cxapi.PATH_METADATA_KEY,constructs_1.Node.of(this).path)}static isCfnResource(construct){return construct.cfnResourceType!==void 0}applyRemovalPolicy(policy,options={}){jsiiDeprecationWarnings.aws_cdk_lib_RemovalPolicy(policy),jsiiDeprecationWarnings.aws_cdk_lib_RemovalPolicyOptions(options),policy=policy||options.default||removal_policy_1.RemovalPolicy.RETAIN;let deletionPolicy;switch(policy){case removal_policy_1.RemovalPolicy.DESTROY:deletionPolicy=cfn_resource_policy_1.CfnDeletionPolicy.DELETE;break;case removal_policy_1.RemovalPolicy.RETAIN:deletionPolicy=cfn_resource_policy_1.CfnDeletionPolicy.RETAIN;break;case removal_policy_1.RemovalPolicy.SNAPSHOT:deletionPolicy=cfn_resource_policy_1.CfnDeletionPolicy.SNAPSHOT;break;default:throw new Error(`Invalid removal policy: ${policy}`)}this.cfnOptions.deletionPolicy=deletionPolicy,options.applyToUpdateReplacePolicy!==!1&&(this.cfnOptions.updateReplacePolicy=deletionPolicy)}getAtt(attributeName){return cfn_reference_1.CfnReference.for(this,attributeName)}addOverride(path,value){const parts=splitOnPeriods(path);let curr=this.rawOverrides;for(;parts.length>1;){const key=parts.shift();curr[key]!=null&&typeof curr[key]=="object"&&!Array.isArray(curr[key])||(curr[key]={}),curr=curr[key]}const lastKey=parts.shift();curr[lastKey]=value}addDeletionOverride(path){this.addOverride(path,void 0)}addPropertyOverride(propertyPath,value){this.addOverride(`Properties.${propertyPath}`,value)}addPropertyDeletionOverride(propertyPath){this.addPropertyOverride(propertyPath,void 0)}addDependsOn(target){jsiiDeprecationWarnings.aws_cdk_lib_CfnResource(target),!!target.shouldSynthesize()&&deps_1.addDependency(this,target,`"${constructs_1.Node.of(this).path}" depends on "${constructs_1.Node.of(target).path}"`)}addMetadata(key,value){this.cfnOptions.metadata||(this.cfnOptions.metadata={}),this.cfnOptions.metadata[key]=value}getMetadata(key){var _b;return(_b=this.cfnOptions.metadata)===null||_b===void 0?void 0:_b[key]}toString(){return`${super.toString()} [${this.cfnResourceType}]`}_addResourceDependency(target){this.dependsOn.add(target)}_toCloudFormation(){if(!this.shouldSynthesize())return{};try{return{Resources:{[this.logicalId]:new util_1.PostResolveToken({Type:this.cfnResourceType,Properties:util_1.ignoreEmpty(this.cfnProperties),DependsOn:util_1.ignoreEmpty(renderDependsOn(this.dependsOn)),CreationPolicy:util_1.capitalizePropertyNames(this,renderCreationPolicy(this.cfnOptions.creationPolicy)),UpdatePolicy:util_1.capitalizePropertyNames(this,this.cfnOptions.updatePolicy),UpdateReplacePolicy:util_1.capitalizePropertyNames(this,this.cfnOptions.updateReplacePolicy),DeletionPolicy:util_1.capitalizePropertyNames(this,this.cfnOptions.deletionPolicy),Version:this.cfnOptions.version,Description:this.cfnOptions.description,Metadata:util_1.ignoreEmpty(this.cfnOptions.metadata),Condition:this.cfnOptions.condition&&this.cfnOptions.condition.logicalId},resourceDef=>{const renderedProps=this.renderProperties(resourceDef.Properties||{});if(renderedProps){const hasDefined=Object.values(renderedProps).find(v=>v!==void 0);resourceDef.Properties=hasDefined!==void 0?renderedProps:void 0}const resolvedRawOverrides=token_1.Tokenization.resolve(this.rawOverrides,{scope:this,resolver:cloudformation_lang_1.CLOUDFORMATION_TOKEN_RESOLVER,removeEmpty:!1});return deepMerge(resourceDef,resolvedRawOverrides)})}}}catch(e){e.message=`While synthesizing ${this.node.path}: ${e.message}`;const trace=this.creationStack;if(trace){const creationStack=["--- resource created at ---",...trace].join(`
  at `),problemTrace=e.stack.substr(e.stack.indexOf(e.message)+e.message.length);e.stack=`${e.message}
  ${creationStack}
  --- problem discovered at ---${problemTrace}`}throw e}function renderDependsOn(dependsOn){return Array.from(dependsOn).sort((x,y)=>x.node.path.localeCompare(y.node.path)).map(r=>r.logicalId)}function renderCreationPolicy(policy){if(!policy)return;const result={...policy};return policy.resourceSignal&&policy.resourceSignal.timeout&&(result.resourceSignal=policy.resourceSignal),result}}get cfnProperties(){const props=this._cfnProperties||{};if(tag_manager_1.TagManager.isTaggable(this)){const tagsProp={};return tagsProp[this.tags.tagPropertyName]=this.tags.renderTags(),deepMerge(props,tagsProp)}return props}renderProperties(props){return props}get updatedProperites(){return this._cfnProperties}validateProperties(_properties){}shouldSynthesize(){return!0}}exports.CfnResource=CfnResource,_a=JSII_RTTI_SYMBOL_1,CfnResource[_a]={fqn:"aws-cdk-lib.CfnResource",version:"2.13.0"};var TagType;(function(TagType2){TagType2.STANDARD="StandardTag",TagType2.AUTOSCALING_GROUP="AutoScalingGroupTag",TagType2.MAP="StringToStringMap",TagType2.KEY_VALUE="KeyValue",TagType2.NOT_TAGGABLE="NotTaggable"})(TagType=exports.TagType||(exports.TagType={}));function deepMerge(target,...sources){for(const source of sources){if(typeof source!="object"||typeof target!="object")throw new Error(`Invalid usage. Both source (${JSON.stringify(source)}) and target (${JSON.stringify(target)}) must be objects`);for(const key of Object.keys(source)){const value=source[key];if(typeof value=="object"&&value!=null&&!Array.isArray(value)){typeof target[key]!="object"&&(target[key]={}),deepMerge(target[key],value);const output=target[key];typeof output=="object"&&Object.keys(output).length===0&&delete target[key]}else value===void 0?delete target[key]:target[key]=value}}return target}function splitOnPeriods(x){const ret=[""];for(let i=0;i<x.length;i++)x[i]==="\\"&&i+1<x.length?(ret[0]+=x[i+1],i++):x[i]==="."?ret.unshift(""):ret[0]+=x[i];return ret.reverse(),ret}
//# sourceMappingURL=cfn-resource.js.map
