| | | 1 | | namespace TeleFlow.Telegram.Internal.Options; |
| | | 2 | | |
| | | 3 | | internal static class TelegramLongPollingOptionsValidator |
| | | 4 | | { |
| | | 5 | | public static void Validate(TelegramLongPollingOptions options) |
| | | 6 | | { |
| | 25 | 7 | | ArgumentNullException.ThrowIfNull(options); |
| | | 8 | | |
| | 25 | 9 | | if (options.TimeoutSeconds <= 0) |
| | | 10 | | { |
| | 0 | 11 | | throw new InvalidOperationException("Long polling timeout must be greater than zero."); |
| | | 12 | | } |
| | | 13 | | |
| | 25 | 14 | | if (options.Limit is < 1 or > 100) |
| | | 15 | | { |
| | 0 | 16 | | throw new InvalidOperationException("Long polling limit must be between 1 and 100."); |
| | | 17 | | } |
| | | 18 | | |
| | 25 | 19 | | if (options.AllowedUpdates is null) |
| | | 20 | | { |
| | 1 | 21 | | throw new InvalidOperationException("Long polling allowed updates options must be configured."); |
| | | 22 | | } |
| | | 23 | | |
| | 24 | 24 | | ValidateBackoff(options.Backoff); |
| | 17 | 25 | | } |
| | | 26 | | |
| | | 27 | | private static void ValidateBackoff(TelegramBackoffOptions? options) |
| | | 28 | | { |
| | 24 | 29 | | if (options is null) |
| | | 30 | | { |
| | 1 | 31 | | throw new InvalidOperationException("Long polling backoff options must be configured."); |
| | | 32 | | } |
| | | 33 | | |
| | 23 | 34 | | if (options.MinDelay < TimeSpan.Zero) |
| | | 35 | | { |
| | 1 | 36 | | throw new InvalidOperationException("Long polling backoff minimum delay must not be negative."); |
| | | 37 | | } |
| | | 38 | | |
| | 22 | 39 | | if (options.MaxDelay < TimeSpan.Zero) |
| | | 40 | | { |
| | 1 | 41 | | throw new InvalidOperationException("Long polling backoff maximum delay must not be negative."); |
| | | 42 | | } |
| | | 43 | | |
| | 21 | 44 | | if (options.MaxDelay < options.MinDelay) |
| | | 45 | | { |
| | 1 | 46 | | throw new InvalidOperationException("Long polling backoff maximum delay must be greater than or equal to min |
| | | 47 | | } |
| | | 48 | | |
| | 20 | 49 | | if (options.Factor < 1) |
| | | 50 | | { |
| | 1 | 51 | | throw new InvalidOperationException("Long polling backoff factor must be greater than or equal to one."); |
| | | 52 | | } |
| | | 53 | | |
| | 19 | 54 | | if (options.Jitter is < 0 or > 1) |
| | | 55 | | { |
| | 2 | 56 | | throw new InvalidOperationException("Long polling backoff jitter must be between zero and one."); |
| | | 57 | | } |
| | 17 | 58 | | } |
| | | 59 | | } |