"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.UsagePlan=exports.Period=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),cx_api_1=require("../../cx-api"),apigateway_generated_1=require("./apigateway.generated"),util_1=require("./util");var Period;(function(Period2){Period2.DAY="DAY",Period2.WEEK="WEEK",Period2.MONTH="MONTH"})(Period=exports.Period||(exports.Period={}));class UsagePlanBase extends core_1.Resource{addApiKey(apiKey,options){let id;const prefix="UsagePlanKeyResource";core_1.FeatureFlags.of(this).isEnabled(cx_api_1.APIGATEWAY_USAGEPLANKEY_ORDERINSENSITIVE_ID)?id=`${prefix}:${core_1.Names.nodeUniqueId(apiKey.node)}`:id=this.node.tryFindChild(prefix)?`${prefix}:${core_1.Names.nodeUniqueId(apiKey.node)}`:prefix;const resource=new apigateway_generated_1.CfnUsagePlanKey(this,id,{keyId:apiKey.keyId,keyType:"API_KEY",usagePlanId:this.usagePlanId});options?.overrideLogicalId&&resource.overrideLogicalId(options?.overrideLogicalId)}}class UsagePlan extends UsagePlanBase{constructor(scope,id,props={}){super(scope,id),this.apiStages=new Array;try{jsiiDeprecationWarnings.aws_cdk_lib_aws_apigateway_UsagePlanProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,UsagePlan),error}let resource;resource=new apigateway_generated_1.CfnUsagePlan(this,"Resource",{apiStages:core_1.Lazy.any({produce:()=>this.renderApiStages(this.apiStages)}),description:props.description,quota:this.renderQuota(props),throttle:this.renderThrottle(props.throttle),usagePlanName:props.name}),this.apiStages.push(...props.apiStages||[]),this.usagePlanId=resource.ref,props.apiKey&&this.addApiKey(props.apiKey)}static fromUsagePlanId(scope,id,usagePlanId){class Import extends UsagePlanBase{constructor(){super(scope,id),this.usagePlanId=usagePlanId}}return new Import}addApiStage(apiStage){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_apigateway_UsagePlanPerApiStage(apiStage)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addApiStage),error}this.apiStages.push(apiStage)}renderApiStages(apiStages){if(apiStages&&apiStages.length>0){const stages=[];return apiStages.forEach(apiStage=>{stages.push(this.createStage(apiStage))}),stages}}createStage(apiStage){const stage=apiStage.stage?apiStage.stage.stageName.toString():void 0,apiId=apiStage.stage?apiStage.stage.restApi.restApiId:void 0,throttle=this.renderThrottlePerMethod(apiStage.throttle);return{apiId,stage,throttle}}renderQuota(props){if(props.quota!==void 0){const limit=props.quota?props.quota.limit:void 0;return util_1.validateInteger(limit,"Throttle quota limit"),{limit:limit||void 0,offset:props.quota?props.quota.offset:void 0,period:props.quota?props.quota.period:void 0}}}renderThrottle(props){let ret;if(props!==void 0){const burstLimit=props.burstLimit;util_1.validateInteger(burstLimit,"Throttle burst limit");const rateLimit=props.rateLimit;util_1.validateDouble(rateLimit,"Throttle rate limit"),ret={burstLimit,rateLimit}}return ret}renderThrottlePerMethod(throttlePerMethod){const ret={};return throttlePerMethod&&throttlePerMethod.length>0&&throttlePerMethod.forEach(value=>{const method=value.method,methodId=`${method.resource.path}/${method.httpMethod}`;ret[methodId]=this.renderThrottle(value.throttle)}),ret}}exports.UsagePlan=UsagePlan,_a=JSII_RTTI_SYMBOL_1,UsagePlan[_a]={fqn:"aws-cdk-lib.aws_apigateway.UsagePlan",version:"2.46.0"};
//# sourceMappingURL=usage-plan.js.map
