"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HttpSqsIntegration=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var apigwv2=()=>{var tmp=require("../../../aws-apigatewayv2");return apigwv2=()=>tmp,tmp},iam=()=>{var tmp=require("../../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};class HttpSqsIntegration extends apigwv2().HttpRouteIntegration{props;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_apigatewayv2_integrations.HttpSqsIntegration",version:"2.256.1"};subtype;constructor(id,props){super(id),this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_apigatewayv2_integrations_HttpSqsIntegrationProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,HttpSqsIntegration),error}this.subtype=this.props.subtype??apigwv2().HttpIntegrationSubtype.SQS_SEND_MESSAGE}bind(options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_apigatewayv2_HttpRouteIntegrationBindOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}if(this.props.subtype&&!this.props.subtype.startsWith("SQS-"))throw new(core_1()).ValidationError((0,literal_string_1().lit)`SubtypeStart`,"Subtype must start with `SQS_`",options.scope);const invokeRole=new(iam()).Role(options.scope,"InvokeRole",{assumedBy:new(iam()).ServicePrincipal("apigateway.amazonaws.com")});return invokeRole.addToPolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,sid:"AllowSqsExecution",actions:[this.determineActionBySubtype(options.scope)],resources:[this.props.queue.queueArn]})),{payloadFormatVersion:apigwv2().PayloadFormatVersion.VERSION_1_0,type:apigwv2().HttpIntegrationType.AWS_PROXY,subtype:this.props.subtype??apigwv2().HttpIntegrationSubtype.SQS_SEND_MESSAGE,credentials:apigwv2().IntegrationCredentials.fromRole(invokeRole),connectionType:apigwv2().HttpConnectionType.INTERNET,parameterMapping:this.props.parameterMapping??this.createDefaultParameterMapping(options.scope)}}determineActionBySubtype(scope){switch(this.subtype){case apigwv2().HttpIntegrationSubtype.SQS_SEND_MESSAGE:return"sqs:SendMessage";case apigwv2().HttpIntegrationSubtype.SQS_RECEIVE_MESSAGE:return"sqs:ReceiveMessage";case apigwv2().HttpIntegrationSubtype.SQS_DELETE_MESSAGE:return"sqs:DeleteMessage";case apigwv2().HttpIntegrationSubtype.SQS_PURGE_QUEUE:return"sqs:PurgeQueue";default:throw new(core_1()).ValidationError((0,literal_string_1().lit)`UnsupportedSubtype`,`Unsupported subtype: ${this.subtype}`,scope)}}createDefaultParameterMapping(scope){switch(this.subtype){case apigwv2().HttpIntegrationSubtype.SQS_SEND_MESSAGE:return new(apigwv2()).ParameterMapping().custom("QueueUrl",this.props.queue.queueUrl).custom("MessageBody","$request.body.MessageBody");case apigwv2().HttpIntegrationSubtype.SQS_RECEIVE_MESSAGE:return new(apigwv2()).ParameterMapping().custom("QueueUrl",this.props.queue.queueUrl);case apigwv2().HttpIntegrationSubtype.SQS_DELETE_MESSAGE:return new(apigwv2()).ParameterMapping().custom("QueueUrl",this.props.queue.queueUrl).custom("ReceiptHandle","$request.body.ReceiptHandle");case apigwv2().HttpIntegrationSubtype.SQS_PURGE_QUEUE:return new(apigwv2()).ParameterMapping().custom("QueueUrl",this.props.queue.queueUrl);default:throw new(core_1()).ValidationError((0,literal_string_1().lit)`UnsupportedSubtype`,`Unsupported subtype: ${this.subtype}`,scope)}}}exports.HttpSqsIntegration=HttpSqsIntegration;
