using Nexus.Api.DTOs; namespace Nexus.Api.Services; /// /// Compatibility adapter for the existing calendar API. Its data now comes /// exclusively from the real OpenClaw cron control plane; disconnected or /// unsupported Gateways return an empty list instead of fabricated jobs. /// public sealed class CalendarService( IOpenClawControlService openClaw) : ICalendarService { public async Task> GetCronJobsAsync( CancellationToken ct = default) { var response = await openClaw.GetCronJobsAsync(200, ct); return response.Items .Select(job => new CronJobEntry( job.Id, job.Name, job.Schedule, job.LastRunAt?.ToString("O") ?? string.Empty, job.NextRunAt?.ToString("O") ?? string.Empty, job.Status)) .ToArray(); } public async Task> GetUpcomingCronJobsAsync( CancellationToken ct = default) { var response = await openClaw.GetCronJobsAsync(200, ct); return response.Items .Where(job => job.Enabled && job.NextRunAt is not null) .OrderBy(job => job.NextRunAt) .Select(job => new UpcomingCronEntry( job.Id, job.Name, job.NextRunAt!.Value.ToString("O"), job.Schedule)) .ToArray(); } }