using System.ComponentModel.DataAnnotations; using Cleanuparr.Infrastructure.Utilities; namespace Cleanuparr.Infrastructure.Models; /// /// Represents the unit of time for job scheduling intervals /// public enum ScheduleUnit { Seconds, Minutes, Hours } /// /// Represents a user-friendly job schedule format /// public class JobSchedule { /// /// The numeric interval value /// public int Every { get; set; } /// /// The unit of time for the interval (seconds, minutes, or hours) /// public ScheduleUnit Type { get; set; } /// /// Converts the JobSchedule to a Quartz cron expression string /// /// A valid cron expression string public string ToCronExpression() { return CronExpressionConverter.ConvertToCronExpression(this); } /// /// Validates the job schedule against the predefined valid values /// /// Thrown when the value is not valid for the selected unit public void Validate() { if (!ScheduleOptions.IsValidValue(Type, Every)) { var validValues = string.Join(", ", ScheduleOptions.GetValidValues(Type)); throw new ValidationException($"Invalid value for {Type}: {Every}. Valid values are: {validValues}"); } } }