"use strict";var _a,_b;Object.defineProperty(exports,"__esModule",{value:!0}),exports.GatewayRouteSpec=exports.GatewayRouteHostnameMatch=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),http_route_path_match_1=require("./http-route-path-match"),utils_1=require("./private/utils"),shared_interfaces_1=require("./shared-interfaces");class GatewayRouteHostnameMatch{static exactly(name){return new GatewayRouteHostnameMatchImpl({exact:name})}static endsWith(suffix){return new GatewayRouteHostnameMatchImpl({suffix})}}exports.GatewayRouteHostnameMatch=GatewayRouteHostnameMatch,_a=JSII_RTTI_SYMBOL_1,GatewayRouteHostnameMatch[_a]={fqn:"aws-cdk-lib.aws_appmesh.GatewayRouteHostnameMatch",version:"2.21.0"};class GatewayRouteHostnameMatchImpl extends GatewayRouteHostnameMatch{constructor(matchProperty){super(),this.matchProperty=matchProperty}bind(_scope){return{hostnameMatch:this.matchProperty}}}class GatewayRouteSpec{static http(options){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_HttpGatewayRouteSpecOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.http),error}return new HttpGatewayRouteSpec(options,shared_interfaces_1.Protocol.HTTP)}static http2(options){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_HttpGatewayRouteSpecOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.http2),error}return new HttpGatewayRouteSpec(options,shared_interfaces_1.Protocol.HTTP2)}static grpc(options){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_GrpcGatewayRouteSpecOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grpc),error}return new GrpcGatewayRouteSpec(options)}}exports.GatewayRouteSpec=GatewayRouteSpec,_b=JSII_RTTI_SYMBOL_1,GatewayRouteSpec[_b]={fqn:"aws-cdk-lib.aws_appmesh.GatewayRouteSpec",version:"2.21.0"};class HttpGatewayRouteSpec extends GatewayRouteSpec{constructor(options,protocol){super(),this.routeTarget=options.routeTarget,this.routeType=protocol,this.match=options.match,this.priority=options.priority}bind(scope){var _c,_d,_e,_f,_g,_h,_j,_k,_l,_m;const pathMatchConfig=((_d=(_c=this.match)===null||_c===void 0?void 0:_c.path)!==null&&_d!==void 0?_d:http_route_path_match_1.HttpGatewayRoutePathMatch.startsWith("/")).bind(scope),rewriteRequestHostname=(_e=this.match)===null||_e===void 0?void 0:_e.rewriteRequestHostname,prefixPathRewrite=pathMatchConfig.prefixPathRewrite,wholePathRewrite=pathMatchConfig.wholePathRewrite,httpConfig={match:{prefix:pathMatchConfig.prefixPathMatch,path:pathMatchConfig.wholePathMatch,hostname:(_g=(_f=this.match)===null||_f===void 0?void 0:_f.hostname)===null||_g===void 0?void 0:_g.bind(scope).hostnameMatch,method:(_h=this.match)===null||_h===void 0?void 0:_h.method,headers:(_k=(_j=this.match)===null||_j===void 0?void 0:_j.headers)===null||_k===void 0?void 0:_k.map(header=>header.bind(scope).headerMatch),queryParameters:(_m=(_l=this.match)===null||_l===void 0?void 0:_l.queryParameters)===null||_m===void 0?void 0:_m.map(queryParameter=>queryParameter.bind(scope).queryParameterMatch)},action:{target:{virtualService:{virtualServiceName:this.routeTarget.virtualServiceName}},rewrite:rewriteRequestHostname!==void 0||prefixPathRewrite||wholePathRewrite?{hostname:rewriteRequestHostname===void 0?void 0:{defaultTargetHostname:rewriteRequestHostname?"ENABLED":"DISABLED"},prefix:prefixPathRewrite,path:wholePathRewrite}:void 0}};return{priority:this.priority,httpSpecConfig:this.routeType===shared_interfaces_1.Protocol.HTTP?httpConfig:void 0,http2SpecConfig:this.routeType===shared_interfaces_1.Protocol.HTTP2?httpConfig:void 0}}}class GrpcGatewayRouteSpec extends GatewayRouteSpec{constructor(options){super(),this.match=options.match,this.routeTarget=options.routeTarget,this.priority=options.priority}bind(scope){var _c;const metadataMatch=this.match.metadata;return utils_1.validateGrpcGatewayRouteMatch(this.match),utils_1.validateGrpcMatchArrayLength(metadataMatch),{grpcSpecConfig:{match:{serviceName:this.match.serviceName,hostname:(_c=this.match.hostname)===null||_c===void 0?void 0:_c.bind(scope).hostnameMatch,metadata:metadataMatch==null?void 0:metadataMatch.map(metadata=>metadata.bind(scope).headerMatch)},action:{target:{virtualService:{virtualServiceName:this.routeTarget.virtualServiceName}},rewrite:this.match.rewriteRequestHostname===void 0?void 0:{hostname:{defaultTargetHostname:this.match.rewriteRequestHostname?"ENABLED":"DISABLED"}}}},priority:this.priority}}}
//# sourceMappingURL=gateway-route-spec.js.map
