"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Schedule=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");class Schedule{constructor(){}static expression(expression){return new LiteralSchedule(expression)}static rate(duration){if(jsiiDeprecationWarnings.aws_cdk_lib_Duration(duration),duration.isUnresolved()){if(["minute","minutes","hour","hours","day","days"].indexOf(duration.unitLabel())===-1)throw new Error("Allowed units for scheduling are: 'minute', 'minutes', 'hour', 'hours', 'day', 'days'");return new LiteralSchedule(`rate(${duration.formatTokenToNumber()})`)}if(duration.toSeconds()===0)throw new Error("Duration cannot be 0");let rate=maybeRate(duration.toDays({integral:!1}),"day");return rate===void 0&&(rate=maybeRate(duration.toHours({integral:!1}),"hour")),rate===void 0&&(rate=makeRate(duration.toMinutes({integral:!0}),"minute")),new LiteralSchedule(rate)}static cron(options){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_events_CronOptions(options),options.weekDay!==void 0&&options.day!==void 0)throw new Error("Cannot supply both 'day' and 'weekDay', use at most one");const minute=fallback(options.minute,"*"),hour=fallback(options.hour,"*"),month=fallback(options.month,"*"),year=fallback(options.year,"*"),day=fallback(options.day,options.weekDay!==void 0?"?":"*"),weekDay=fallback(options.weekDay,"?");return new LiteralSchedule(`cron(${minute} ${hour} ${day} ${month} ${weekDay} ${year})`)}}exports.Schedule=Schedule,_a=JSII_RTTI_SYMBOL_1,Schedule[_a]={fqn:"aws-cdk-lib.aws_events.Schedule",version:"2.13.0"};class LiteralSchedule extends Schedule{constructor(expressionString){super();this.expressionString=expressionString}}function fallback(x,def){return x!=null?x:def}function maybeRate(interval,singular){if(!(interval===0||!Number.isInteger(interval)))return makeRate(interval,singular)}function makeRate(interval,singular){return interval===1?`rate(1 ${singular})`:`rate(${interval} ${singular}s)`}
//# sourceMappingURL=schedule.js.map
