namespace AIStudio.Tools.Pauses; /// /// The bounds of a random pause, e.g., between two indexing steps, cf. PauseBetweenSteps. /// /// The shortest pause. Between the shortest limit of the feature and MaximumSeconds. /// The longest pause, which may be drawn as well. At most the longest limit of the feature. public sealed record PauseRange(int MinimumSeconds, int MaximumSeconds) { /// /// No pause at all, which is the default of the indexing. /// public static readonly PauseRange NONE = new(0, 0); /// /// Whether the next step starts right away. /// public bool IsNone => this.MaximumSeconds is 0; /// /// Works out the bounds which apply, so that the lower one never exceeds the upper one. /// /// /// Both bounds are moved into the limits of the feature first. A bound which a configuration plugin /// locks wins, and the other one adjusts to it. A bound the plugin only presets counts like one the /// user set. Otherwise, the lower bound wins, i.e., the longer pause: it spares the server, which /// is what the pause is for. That holds as well when a plugin locks both bounds the wrong way round.

/// /// Which bound is locked matters only while the bounds are the wrong way round. Asking reads the /// managed state of the whole app, which bounds in order do without, so the locks are asked only then. ///
/// The shortest and the longest pause the feature allows. /// The lower bound as set. /// Whether a configuration plugin locks the lower bound. /// The upper bound as set. /// Whether a configuration plugin locks the upper bound. /// The bounds which apply. public static PauseRange GetEffective(PauseLimits limits, int minimumSeconds, Func isMinimumLocked, int maximumSeconds, Func isMaximumLocked) { var minimum = limits.Clamp(minimumSeconds); var maximum = limits.Clamp(maximumSeconds); if (minimum <= maximum) return new(minimum, maximum); if (isMaximumLocked() && !isMinimumLocked()) return new(maximum, maximum); return new(minimum, minimum); } }