using System.Collections.Generic; using System.Linq; using FluentValidation; using MfGames.Gallium; using MfGames.Nitride.Generators; namespace MfGames.Nitride.Temporal.Schedules; public enum SchedulePeriod { /// /// Indicates that all the matching schedule periods are instant (zero time). /// Instant, /// /// Indicates that the entities will be scheduled a day apart. /// Day, /// /// Indicates that the entities will be scheduled seven days apart. /// Week, } /// /// Applies schedules against the list of entities. /// [WithProperties] public partial class ApplySchedules : OperationBase { private readonly IValidator validator; public ApplySchedules( IValidator validator, Timekeeper timekeeper) { this.Timekeeper = timekeeper; this.validator = validator; this.Schedules = new List(); } /// /// Gets or sets the ordered list of schedules to apply to the entities. /// public IList Schedules { get; set; } /// /// Gets or sets the timekeeper associated with this operation. /// public Timekeeper Timekeeper { get; set; } /// public override IEnumerable Run(IEnumerable input) { this.validator.ValidateAndThrow(this); return input.Select(this.Apply); } public ApplySchedules WithSchedules(IEnumerable items) where TItem : ISchedule { this.Schedules = items.OfType().ToList(); return this; } private Entity Apply(Entity entity) { foreach (ISchedule schedule in this.Schedules) { if (!schedule.CanApply(entity)) { continue; } entity = schedule.Apply(entity, this.Timekeeper); } return entity; } }