using Connected.Middleware.Annotations; using Connected.Notifications; using Connected.Notifications.Events; using Connected.ServiceModel; using Logistics.Documents.Receive; using Microsoft.Extensions.Logging; namespace Logistics.Documents.Listeners; [Middleware(nameof(IReceiveDocumentService.ItemUpdated))] internal sealed class ReceiveItemListener : EventListener> { public ReceiveItemListener(ILogger logger, IReceiveDocumentService documents) { Logger = logger; Documents = documents; } private ILogger Logger { get; } private IReceiveDocumentService Documents { get; } protected override async Task OnInvoke() { if (await Documents.SelectItem(Arguments.Id) is not IReceiveItem item) { Logger.LogWarning("The IReceiveItem not found ({id}}.", Arguments.Id); return; } var items = await Documents.QueryItems(item.Document); await Documents.Patch(new PatchArgs { Id = item.Document, Properties = new Dictionary { {nameof(IReceiveDocument.OpenItemCount), items.Count(f=>f.PostedQuantity