"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.SqsEventSource=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class SqsEventSource{constructor(queue,props={}){this.queue=queue,this.props=props,this._eventSourceMappingId=void 0,this._eventSourceMappingArn=void 0;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sqs_IQueue(queue),jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_event_sources_SqsEventSourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,SqsEventSource),error}if(this.props.maxBatchingWindow!==void 0){if(queue.fifo)throw new Error("Batching window is not supported for FIFO queues");if(!this.props.maxBatchingWindow.isUnresolved()&&this.props.maxBatchingWindow.toSeconds()>300)throw new Error(`Maximum batching window must be 300 seconds or less (given ${this.props.maxBatchingWindow.toHumanString()})`)}if(this.props.batchSize!==void 0&&!core_1().Token.isUnresolved(this.props.batchSize)){if(this.props.maxBatchingWindow!==void 0&&(this.props.batchSize<1||this.props.batchSize>1e4))throw new Error(`Maximum batch size must be between 1 and 10000 inclusive (given ${this.props.batchSize}) when batching window is specified.`);if(this.props.maxBatchingWindow===void 0&&(this.props.batchSize<1||this.props.batchSize>10))throw new Error(`Maximum batch size must be between 1 and 10 inclusive (given ${this.props.batchSize}) when batching window is not specified.`)}}bind(target){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(target)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const eventSourceMapping=target.addEventSourceMapping(`SqsEventSource:${core_1().Names.nodeUniqueId(this.queue.node)}`,{batchSize:this.props.batchSize,maxBatchingWindow:this.props.maxBatchingWindow,maxConcurrency:this.props.maxConcurrency,reportBatchItemFailures:this.props.reportBatchItemFailures,enabled:this.props.enabled,eventSourceArn:this.queue.queueArn,filters:this.props.filters,filterEncryption:this.props.filterEncryption});this._eventSourceMappingId=eventSourceMapping.eventSourceMappingId,this._eventSourceMappingArn=eventSourceMapping.eventSourceMappingArn,target.role?this.queue.grantConsumeMessages(target):core_1().Annotations.of(target).addWarningV2("@aws-cdk/aws-lambda-event-sources:sqsFunctionImportWithoutRole",`Function '${target.node.path}' was imported without an IAM role so it was not granted access to consume messages from '${this.queue.node.path}'`)}get eventSourceMappingId(){if(!this._eventSourceMappingId)throw new Error("SqsEventSource is not yet bound to an event source mapping");return this._eventSourceMappingId}get eventSourceMappingArn(){if(!this._eventSourceMappingArn)throw new Error("SqsEventSource is not yet bound to an event source mapping");return this._eventSourceMappingArn}}exports.SqsEventSource=SqsEventSource,_a=JSII_RTTI_SYMBOL_1,SqsEventSource[_a]={fqn:"aws-cdk-lib.aws_lambda_event_sources.SqsEventSource",version:"2.159.0"};
