using System.Collections.Generic; using CommunityToolkit.Mvvm.Messaging; using Wino.Core.Domain.Entities.Calendar; using Wino.Core.Domain.Enums; using Wino.Core.Domain.Models.Requests; using Wino.Messaging.Client.Calendar; namespace Wino.Core.Requests.Calendar; /// /// Request to update an existing calendar event on the server. /// The calendar item should be already updated in the local database before queuing this request. /// public record UpdateCalendarEventRequest(CalendarItem Item, List Attendees) : CalendarRequestBase(Item) { /// /// Original attendees before the update, used for reverting changes if the update fails. /// public List OriginalAttendees { get; init; } /// /// Original calendar item state before the update, used for reverting changes if the update fails. /// public CalendarItem OriginalItem { get; init; } public override CalendarSynchronizerOperation Operation => CalendarSynchronizerOperation.UpdateEvent; /// /// After successful update, we need to resync to ensure changes are properly reflected. /// public override int ResynchronizationDelay => 2000; public override void ApplyUIChanges() { // Notify UI that the event was updated locally WeakReferenceMessenger.Default.Send(new CalendarItemUpdated(Item, CalendarItemUpdateSource.ClientUpdated)); } public override void RevertUIChanges() { // If update fails, restore the original state if (OriginalItem != null && OriginalAttendees != null) { // Send the original item back to restore UI state WeakReferenceMessenger.Default.Send(new CalendarItemUpdated(OriginalItem, CalendarItemUpdateSource.ClientReverted)); } else { // Fallback: just notify with current item to trigger refresh WeakReferenceMessenger.Default.Send(new CalendarItemUpdated(Item, CalendarItemUpdateSource.ClientReverted)); } } }