"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateScheduleCommand = void 0; const Result_1 = require("../../../../shared/domain/Result"); const Schedule_1 = require("../../domain/entities/Schedule"); class CreateScheduleCommand { constructor(scheduleRepo, eventBus) { this.scheduleRepo = scheduleRepo; this.eventBus = eventBus; } async execute(req) { const result = Schedule_1.Schedule.create(req); if (!result.ok) return (0, Result_1.Err)(result.error); const schedule = result.value; await this.scheduleRepo.save(schedule); for (const event of schedule.domainEvents) { await this.eventBus.publish(event); } schedule.clearEvents(); return (0, Result_1.Ok)({ id: schedule.id.toString(), name: schedule.name, url: schedule.url, cronExpression: schedule.cronExpression.value, enabled: schedule.enabled, nextRunAt: schedule.nextRunAt, createdAt: schedule.createdAt, }); } } exports.CreateScheduleCommand = CreateScheduleCommand;