"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LambdaSubscription=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),constructs_1=require("constructs"),iam=require("../../aws-iam"),sns=require("../../aws-sns"),core_1=require("../../core");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.96.1"};
