var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { BaseEntity } from "@memberjunction/core";
import { MJScheduledActionEntity } from "../generated/entity_subclasses.js";
import { RegisterClass } from "@memberjunction/global";
let MJScheduledActionEntityExtended = class MJScheduledActionEntityExtended extends MJScheduledActionEntity {
    constructor() {
        super(...arguments);
        this._params = [];
    }
    async Save(options) {
        // The purpose of this override is to generate the the CronExpression field in the ScheduledAction entity
        // based on the settings we have for Type/IntervalDays/DayOfWeek/DayOfMonth/Month
        // we only generate the CronExpression if the Type != Custom
        if (this.Type !== 'Custom') {
            let cronExpression = '';
            if (this.Type === 'Daily') {
                cronExpression = `0 0 0 * * ?`;
            }
            else if (this.Type === 'Weekly') {
                cronExpression = `0 0 0 ? * ${this.DayOfWeek}`;
            }
            else if (this.Type === 'Monthly') {
                cronExpression = `0 0 0 ${this.DayOfMonth} * ?`;
            }
            else if (this.Type === 'Yearly') {
                cronExpression = `0 0 0 ${this.DayOfMonth} ${this.Month} ?`;
            }
            this.CronExpression = cronExpression;
        }
        // does the cronexpression need to use the Timezone field we have?
        return await super.Save(options);
    }
    get Params() {
        return this._params;
    }
    set Params(value) {
        this._params = value;
    }
};
MJScheduledActionEntityExtended = __decorate([
    RegisterClass(BaseEntity, 'MJ: Scheduled Actions')
], MJScheduledActionEntityExtended);
export { MJScheduledActionEntityExtended };
//# sourceMappingURL=MJScheduledActionEntityExtended.js.map