"use strict";var _a,_b;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ValidationMethod=exports.Certificate=exports.CertificateValidation=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),certificate_base_1=require("./certificate-base"),certificatemanager_generated_1=require("./certificatemanager.generated"),util_1=require("./util");class CertificateValidation{constructor(props){var _c;this.props=props,this.method=(_c=props.method)!==null&&_c!==void 0?_c:ValidationMethod.EMAIL}static fromDns(hostedZone){return jsiiDeprecationWarnings.aws_cdk_lib_aws_route53_IHostedZone(hostedZone),new CertificateValidation({method:ValidationMethod.DNS,hostedZone})}static fromDnsMultiZone(hostedZones){return new CertificateValidation({method:ValidationMethod.DNS,hostedZones})}static fromEmail(validationDomains){return new CertificateValidation({method:ValidationMethod.EMAIL,validationDomains})}}exports.CertificateValidation=CertificateValidation,_a=JSII_RTTI_SYMBOL_1,CertificateValidation[_a]={fqn:"aws-cdk-lib.aws_certificatemanager.CertificateValidation",version:"2.13.0"};class Certificate extends certificate_base_1.CertificateBase{constructor(scope,id,props){super(scope,id);jsiiDeprecationWarnings.aws_cdk_lib_aws_certificatemanager_CertificateProps(props);let validation;props.validation?validation=props.validation:props.validationMethod===ValidationMethod.DNS?validation=CertificateValidation.fromDns():validation=CertificateValidation.fromEmail(props.validationDomains);const allDomainNames=[props.domainName].concat(props.subjectAlternativeNames||[]),cert=new certificatemanager_generated_1.CfnCertificate(this,"Resource",{domainName:props.domainName,subjectAlternativeNames:props.subjectAlternativeNames,domainValidationOptions:renderDomainValidation(validation,allDomainNames),validationMethod:validation.method});this.certificateArn=cert.ref}static fromCertificateArn(scope,id,certificateArn){class Import extends certificate_base_1.CertificateBase{constructor(){super(...arguments);this.certificateArn=certificateArn}}return new Import(scope,id)}}exports.Certificate=Certificate,_b=JSII_RTTI_SYMBOL_1,Certificate[_b]={fqn:"aws-cdk-lib.aws_certificatemanager.Certificate",version:"2.13.0"};var ValidationMethod;(function(ValidationMethod2){ValidationMethod2.EMAIL="EMAIL",ValidationMethod2.DNS="DNS"})(ValidationMethod=exports.ValidationMethod||(exports.ValidationMethod={}));function renderDomainValidation(validation,domainNames){var _c,_d,_e;const domainValidation=[];switch(validation.method){case ValidationMethod.DNS:for(const domainName of getUniqueDnsDomainNames(domainNames)){const hostedZone=(_d=(_c=validation.props.hostedZones)===null||_c===void 0?void 0:_c[domainName])!==null&&_d!==void 0?_d:validation.props.hostedZone;hostedZone&&domainValidation.push({domainName,hostedZoneId:hostedZone.hostedZoneId})}break;case ValidationMethod.EMAIL:for(const domainName of domainNames){const validationDomain=(_e=validation.props.validationDomains)===null||_e===void 0?void 0:_e[domainName];if(!validationDomain&&core_1.Token.isUnresolved(domainName))throw new Error("When using Tokens for domain names, 'validationDomains' needs to be supplied");domainValidation.push({domainName,validationDomain:validationDomain!=null?validationDomain:util_1.apexDomain(domainName)})}break;default:throw new Error(`Unknown validation method ${validation.method}`)}return domainValidation.length!==0?domainValidation:void 0}function getUniqueDnsDomainNames(domainNames){return domainNames.filter(domain=>core_1.Token.isUnresolved(domain)||!domain.startsWith("*.")||!domainNames.includes(domain.replace("*.","")))}
//# sourceMappingURL=certificate.js.map
