| | | 1 | | namespace TeleFlow.Telegram.Internal; |
| | | 2 | | |
| | | 3 | | internal static class TelegramRawLongPollingOptionsValidator |
| | | 4 | | { |
| | | 5 | | public static void Validate(TelegramRawLongPollingOptions options) |
| | | 6 | | { |
| | 24 | 7 | | ArgumentNullException.ThrowIfNull(options); |
| | | 8 | | |
| | 24 | 9 | | if (options.TimeoutSeconds <= 0) |
| | | 10 | | { |
| | 0 | 11 | | throw new InvalidOperationException("Raw long polling timeout must be greater than zero."); |
| | | 12 | | } |
| | | 13 | | |
| | 24 | 14 | | if (options.Limit is < 1 or > 100) |
| | | 15 | | { |
| | 0 | 16 | | throw new InvalidOperationException("Raw long polling limit must be between 1 and 100."); |
| | | 17 | | } |
| | | 18 | | |
| | 24 | 19 | | ValidateAllowedUpdates(options.AllowedUpdates); |
| | 22 | 20 | | TelegramRawLongPollingBackoff.ValidateOptions(options.Backoff); |
| | 22 | 21 | | } |
| | | 22 | | |
| | | 23 | | private static void ValidateAllowedUpdates(IReadOnlyList<string>? allowedUpdates) |
| | | 24 | | { |
| | 24 | 25 | | if (allowedUpdates is null) |
| | | 26 | | { |
| | 15 | 27 | | return; |
| | | 28 | | } |
| | | 29 | | |
| | 95 | 30 | | foreach (var updateType in allowedUpdates) |
| | | 31 | | { |
| | 39 | 32 | | if (string.IsNullOrWhiteSpace(updateType)) |
| | | 33 | | { |
| | 1 | 34 | | throw new InvalidOperationException("Raw long polling allowed update values must not be empty."); |
| | | 35 | | } |
| | | 36 | | } |
| | | 37 | | |
| | 8 | 38 | | var duplicate = allowedUpdates |
| | 37 | 39 | | .GroupBy(static updateType => updateType, StringComparer.Ordinal) |
| | 44 | 40 | | .FirstOrDefault(static group => group.Count() > 1); |
| | | 41 | | |
| | 8 | 42 | | if (duplicate is not null) |
| | | 43 | | { |
| | 1 | 44 | | throw new InvalidOperationException( |
| | 1 | 45 | | $"Duplicate raw long polling allowed update value '{duplicate.Key}' was specified."); |
| | | 46 | | } |
| | 7 | 47 | | } |
| | | 48 | | } |