"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Peer=void 0;const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var connections_1=()=>{var tmp=require("./connections");return connections_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class Peer{static ipv4(cidrIp){return new CidrIPv4(cidrIp)}static anyIpv4(){return new AnyIPv4}static ipv6(cidrIp){return new CidrIPv6(cidrIp)}static anyIpv6(){return new AnyIPv6}static prefixList(prefixListId){return new PrefixList(prefixListId)}static securityGroupId(securityGroupId,sourceSecurityGroupOwnerId){return new SecurityGroupId(securityGroupId,sourceSecurityGroupOwnerId)}constructor(){}}exports.Peer=Peer,_a=JSII_RTTI_SYMBOL_1,Peer[_a]={fqn:"aws-cdk-lib.aws_ec2.Peer",version:"2.148.1"};class CidrIPv4{constructor(cidrIp){if(this.cidrIp=cidrIp,this.canInlineRule=!0,this.connections=new(connections_1()).Connections({peer:this}),!core_1().Token.isUnresolved(cidrIp)){const cidrMatch=cidrIp.match(/^(\d{1,3}\.){3}\d{1,3}(\/\d+)?$/);if(!cidrMatch)throw new Error(`Invalid IPv4 CIDR: "${cidrIp}"`);if(!cidrMatch[2])throw new Error(`CIDR mask is missing in IPv4: "${cidrIp}". Did you mean "${cidrIp}/32"?`)}this.uniqueId=cidrIp}toIngressRuleConfig(){return{cidrIp:this.cidrIp}}toEgressRuleConfig(){return{cidrIp:this.cidrIp}}}class AnyIPv4 extends CidrIPv4{constructor(){super("0.0.0.0/0")}}class CidrIPv6{constructor(cidrIpv6){if(this.cidrIpv6=cidrIpv6,this.canInlineRule=!0,this.connections=new(connections_1()).Connections({peer:this}),!core_1().Token.isUnresolved(cidrIpv6)){const cidrMatch=cidrIpv6.match(/^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/);if(!cidrMatch)throw new Error(`Invalid IPv6 CIDR: "${cidrIpv6}"`);if(!cidrMatch[3])throw new Error(`CIDR mask is missing in IPv6: "${cidrIpv6}". Did you mean "${cidrIpv6}/128"?`)}this.uniqueId=cidrIpv6}toIngressRuleConfig(){return{cidrIpv6:this.cidrIpv6}}toEgressRuleConfig(){return{cidrIpv6:this.cidrIpv6}}}class AnyIPv6 extends CidrIPv6{constructor(){super("::/0")}}class PrefixList{constructor(prefixListId){this.prefixListId=prefixListId,this.canInlineRule=!1,this.connections=new(connections_1()).Connections({peer:this}),this.uniqueId=prefixListId}toIngressRuleConfig(){return{sourcePrefixListId:this.prefixListId}}toEgressRuleConfig(){return{destinationPrefixListId:this.prefixListId}}}class SecurityGroupId{constructor(securityGroupId,sourceSecurityGroupOwnerId){if(this.securityGroupId=securityGroupId,this.sourceSecurityGroupOwnerId=sourceSecurityGroupOwnerId,this.canInlineRule=!0,this.connections=new(connections_1()).Connections({peer:this}),!core_1().Token.isUnresolved(securityGroupId)&&!securityGroupId.match(/^sg-[a-z0-9]{8,17}$/))throw new Error(`Invalid security group ID: "${securityGroupId}"`);if(sourceSecurityGroupOwnerId&&!core_1().Token.isUnresolved(sourceSecurityGroupOwnerId)&&!sourceSecurityGroupOwnerId.match(/^[0-9]{12}$/))throw new Error(`Invalid security group owner ID: "${sourceSecurityGroupOwnerId}"`);this.uniqueId=securityGroupId}toIngressRuleConfig(){return{sourceSecurityGroupId:this.securityGroupId,...this.sourceSecurityGroupOwnerId&&{sourceSecurityGroupOwnerId:this.sourceSecurityGroupOwnerId}}}toEgressRuleConfig(){return{destinationSecurityGroupId:this.securityGroupId}}}
