| | | 1 | | namespace Services.FeedPriceServices; |
| | | 2 | | |
| | | 3 | | /// <summary>Выбирает из расшифровок по кабинетам сборку клиента заказа.</summary> |
| | | 4 | | public static class FeedOrderExplanationPicker |
| | | 5 | | { |
| | | 6 | | public static FeedOrderExplanation Pick(FeedExplanationResult result, int keyCount, string? clientName) |
| | | 7 | | { |
| | 6 | 8 | | var cabinet = FeedCabinets.ForClientName(clientName); |
| | | 9 | | FeedOrderExplanation Result(FeedOrderState state, FeedExplanation? selected = null) => new() |
| | | 10 | | { |
| | | 11 | | State = state, |
| | | 12 | | Key = result.Key, |
| | | 13 | | Client = clientName, |
| | | 14 | | Cabinet = cabinet, |
| | | 15 | | Selected = selected, |
| | | 16 | | Explanations = result.Explanations, |
| | | 17 | | Error = result.Error |
| | | 18 | | }; |
| | | 19 | | |
| | | 20 | | // «Нет ключа» известно до запроса; при недоступном фиде «нет кабинета» и «нет в фиде» были бы неверным диагнозо |
| | 7 | 21 | | if (keyCount == 0) return Result(FeedOrderState.NoKey); |
| | 6 | 22 | | if (result.Error is not null) return Result(FeedOrderState.Error); |
| | 6 | 23 | | if (cabinet is null) return Result(FeedOrderState.NoCabinet); |
| | | 24 | | |
| | 2 | 25 | | var selected = result.Explanations |
| | 4 | 26 | | .Where(x => x.Found && string.Equals(x.Cabinet, cabinet, StringComparison.OrdinalIgnoreCase)) |
| | 1 | 27 | | .OrderByDescending(x => x.RunId) |
| | 2 | 28 | | .FirstOrDefault(); |
| | | 29 | | |
| | 2 | 30 | | return selected is null ? Result(FeedOrderState.NotInFeed) : Result(FeedOrderState.Ok, selected); |
| | | 31 | | } |
| | | 32 | | } |