"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LambdaSubscription=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},sns=()=>{var tmp=require("../../aws-sns");return sns=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class LambdaSubscription{constructor(fn,props={}){this.fn=fn,this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(fn),jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_subscriptions_LambdaSubscriptionProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,LambdaSubscription),error}}bind(topic){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sns_ITopic(topic)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}if(!constructs_1().Construct.isConstruct(this.fn))throw new Error("The supplied lambda Function object must be an instance of Construct");return this.fn.addPermission(`AllowInvoke:${core_1().Names.nodeUniqueId(topic.node)}`,{sourceArn:topic.topicArn,principal:new(iam()).ServicePrincipal("sns.amazonaws.com")}),topic instanceof sns().Topic&&topic.stack!==this.fn.stack&&this.fn.stack.addDependency(topic.stack),{subscriberScope:this.fn,subscriberId:topic.node.id,endpoint:this.fn.functionArn,protocol:sns().SubscriptionProtocol.LAMBDA,filterPolicy:this.props.filterPolicy,filterPolicyWithMessageBody:this.props.filterPolicyWithMessageBody,region:this.regionFromArn(topic),deadLetterQueue:this.props.deadLetterQueue}}regionFromArn(topic){return topic instanceof sns().Topic?topic.stack!==this.fn.stack&&!core_1().Token.isUnresolved(topic.env.region)&&topic.env.region!==this.fn.env.region?topic.env.region:void 0:core_1().Stack.of(topic).splitArn(topic.topicArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).region}}exports.LambdaSubscription=LambdaSubscription,_a=JSII_RTTI_SYMBOL_1,LambdaSubscription[_a]={fqn:"aws-cdk-lib.aws_sns_subscriptions.LambdaSubscription",version:"2.159.0"};
