"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.extractQualifierFromArn=exports.Version=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),function_1=require("./function"),function_base_1=require("./function-base"),lambda_generated_1=require("./lambda.generated"),util_1=require("./util");class Version extends function_base_1.QualifiedFunctionBase{constructor(scope,id,props){super(scope,id);this.canCreatePermissions=!0,jsiiDeprecationWarnings.aws_cdk_lib_aws_lambda_VersionProps(props),this.lambda=props.lambda,this.architecture=props.lambda.architecture;const version=new lambda_generated_1.CfnVersion(this,"Resource",{codeSha256:props.codeSha256,description:props.description,functionName:props.lambda.functionName,provisionedConcurrencyConfig:this.determineProvisionedConcurrency(props)});props.removalPolicy&&version.applyRemovalPolicy(props.removalPolicy,{default:core_1.RemovalPolicy.DESTROY}),this.version=version.attrVersion,this.functionArn=version.ref,this.functionName=`${this.lambda.functionName}:${this.version}`,this.qualifier=version.attrVersion,(props.onFailure||props.onSuccess||props.maxEventAge||props.retryAttempts!==void 0)&&this.configureAsyncInvoke({onFailure:props.onFailure,onSuccess:props.onSuccess,maxEventAge:props.maxEventAge,retryAttempts:props.retryAttempts})}static fromVersionArn(scope,id,versionArn){const version=extractQualifierFromArn(versionArn),lambda=function_1.Function.fromFunctionArn(scope,`${id}Function`,versionArn);class Import extends function_base_1.QualifiedFunctionBase{constructor(){super(...arguments);this.version=version,this.lambda=lambda,this.functionName=`${lambda.functionName}:${version}`,this.functionArn=versionArn,this.grantPrincipal=lambda.grantPrincipal,this.role=lambda.role,this.architecture=lambda.architecture,this.qualifier=version,this.canCreatePermissions=this._isStackAccount()}addAlias(name,opts={}){return util_1.addAlias(this,this,name,opts)}get edgeArn(){if(version==="$LATEST")throw new Error("$LATEST function version cannot be used for Lambda@Edge");return this.functionArn}}return new Import(scope,id)}static fromVersionAttributes(scope,id,attrs){jsiiDeprecationWarnings.aws_cdk_lib_aws_lambda_VersionAttributes(attrs);class Import extends function_base_1.QualifiedFunctionBase{constructor(){super(...arguments);this.version=attrs.version,this.lambda=attrs.lambda,this.functionName=`${attrs.lambda.functionName}:${attrs.version}`,this.functionArn=`${attrs.lambda.functionArn}:${attrs.version}`,this.grantPrincipal=attrs.lambda.grantPrincipal,this.role=attrs.lambda.role,this.architecture=attrs.lambda.architecture,this.qualifier=attrs.version,this.canCreatePermissions=this._isStackAccount()}addAlias(name,opts={}){return util_1.addAlias(this,this,name,opts)}get edgeArn(){if(attrs.version==="$LATEST")throw new Error("$LATEST function version cannot be used for Lambda@Edge");return this.functionArn}}return new Import(scope,id)}get grantPrincipal(){return this.lambda.grantPrincipal}get role(){return this.lambda.role}metric(metricName,props={}){return jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudwatch_MetricOptions(props),super.metric(metricName,{dimensions:{FunctionName:this.lambda.functionName,Resource:`${this.lambda.functionArn}:${this.version}`},...props})}addAlias(aliasName,options={}){return jsiiDeprecationWarnings.aws_cdk_lib_aws_lambda_AliasOptions(options),util_1.addAlias(this,this,aliasName,options)}get edgeArn(){if(this.version==="$LATEST")throw new Error("$LATEST function version cannot be used for Lambda@Edge");return core_1.Lazy.string({produce:()=>(this.lambda instanceof function_1.Function&&this.lambda._checkEdgeCompatibility(),this.functionArn)})}determineProvisionedConcurrency(props){if(!!props.provisionedConcurrentExecutions){if(props.provisionedConcurrentExecutions<=0)throw new Error("provisionedConcurrentExecutions must have value greater than or equal to 1");return{provisionedConcurrentExecutions:props.provisionedConcurrentExecutions}}}}exports.Version=Version,_a=JSII_RTTI_SYMBOL_1,Version[_a]={fqn:"aws-cdk-lib.aws_lambda.Version",version:"2.13.0"};function extractQualifierFromArn(arn){return core_1.Fn.select(7,core_1.Fn.split(":",arn))}exports.extractQualifierFromArn=extractQualifierFromArn;
//# sourceMappingURL=lambda-version.js.map
