"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BackupPlan=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),backup_generated_1=require("./backup.generated"),rule_1=require("./rule"),selection_1=require("./selection"),vault_1=require("./vault");class BackupPlan extends core_1.Resource{constructor(scope,id,props={}){super(scope,id);this.rules=[],jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_BackupPlanProps(props);const plan=new backup_generated_1.CfnBackupPlan(this,"Resource",{backupPlan:{advancedBackupSettings:this.advancedBackupSettings(props),backupPlanName:props.backupPlanName||id,backupPlanRule:core_1.Lazy.any({produce:()=>this.rules},{omitEmptyArray:!0})}});this.backupPlanId=plan.attrBackupPlanId,this.backupPlanArn=plan.attrBackupPlanArn,this.versionId=plan.attrVersionId,this._backupVault=props.backupVault;for(const rule of props.backupPlanRules||[])this.addRule(rule);this.node.addValidation({validate:()=>this.validatePlan()})}static fromBackupPlanId(scope,id,backupPlanId){class Import extends core_1.Resource{constructor(){super(...arguments);this.backupPlanId=backupPlanId}}return new Import(scope,id)}static daily35DayRetention(scope,id,backupVault){jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_IBackupVault(backupVault);const plan=new BackupPlan(scope,id,{backupVault});return plan.addRule(rule_1.BackupPlanRule.daily()),plan}static dailyMonthly1YearRetention(scope,id,backupVault){jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_IBackupVault(backupVault);const plan=new BackupPlan(scope,id,{backupVault});return plan.addRule(rule_1.BackupPlanRule.daily()),plan.addRule(rule_1.BackupPlanRule.monthly1Year()),plan}static dailyWeeklyMonthly5YearRetention(scope,id,backupVault){jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_IBackupVault(backupVault);const plan=new BackupPlan(scope,id,{backupVault});return plan.addRule(rule_1.BackupPlanRule.daily()),plan.addRule(rule_1.BackupPlanRule.weekly()),plan.addRule(rule_1.BackupPlanRule.monthly5Year()),plan}static dailyWeeklyMonthly7YearRetention(scope,id,backupVault){jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_IBackupVault(backupVault);const plan=new BackupPlan(scope,id,{backupVault});return plan.addRule(rule_1.BackupPlanRule.daily()),plan.addRule(rule_1.BackupPlanRule.weekly()),plan.addRule(rule_1.BackupPlanRule.monthly7Year()),plan}advancedBackupSettings(props){if(!!props.windowsVss)return[{backupOptions:{WindowsVSS:"enabled"},resourceType:"EC2"}]}addRule(rule){var _b,_c,_d,_e,_f,_g;jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_BackupPlanRule(rule);let vault;rule.props.backupVault?vault=rule.props.backupVault:this._backupVault?vault=this._backupVault:(this._backupVault=new vault_1.BackupVault(this,"Vault"),vault=this._backupVault),this.rules.push({completionWindowMinutes:(_b=rule.props.completionWindow)===null||_b===void 0?void 0:_b.toMinutes(),lifecycle:(rule.props.deleteAfter||rule.props.moveToColdStorageAfter)&&{deleteAfterDays:(_c=rule.props.deleteAfter)===null||_c===void 0?void 0:_c.toDays(),moveToColdStorageAfterDays:(_d=rule.props.moveToColdStorageAfter)===null||_d===void 0?void 0:_d.toDays()},ruleName:(_e=rule.props.ruleName)!==null&&_e!==void 0?_e:`${this.node.id}Rule${this.rules.length}`,scheduleExpression:(_f=rule.props.scheduleExpression)===null||_f===void 0?void 0:_f.expressionString,startWindowMinutes:(_g=rule.props.startWindow)===null||_g===void 0?void 0:_g.toMinutes(),enableContinuousBackup:rule.props.enableContinuousBackup,targetBackupVault:vault.backupVaultName})}get backupVault(){if(!this._backupVault)throw new Error("No backup vault!");return this._backupVault}addSelection(id,options){return jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_BackupSelectionOptions(options),new selection_1.BackupSelection(this,id,{backupPlan:this,...options})}validatePlan(){return this.rules.length===0?["A backup plan must have at least 1 rule."]:[]}}exports.BackupPlan=BackupPlan,_a=JSII_RTTI_SYMBOL_1,BackupPlan[_a]={fqn:"aws-cdk-lib.aws_backup.BackupPlan",version:"2.13.0"};
//# sourceMappingURL=plan.js.map
