using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Domain.Constants;
using MediatR;
namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Handlers;
///
///
///
public class RemoveHistoryHandler : INotificationHandler
{
private readonly IRepository _repo;
///
///
///
///
public RemoveHistoryHandler(IRepository repository)
{
_repo = repository;
}
///
///
///
///
///
///
public Task Handle(RemoveSignatureNotification notification, CancellationToken cancel)
{
return _repo.DeleteAsync(hists =>
{
hists = hists
.Where(hist => hist.Envelope!.Uuid == notification.EnvelopeUuid)
.Where(hist => hist.Status == EnvelopeStatus.DocumentSigned);
if (notification.ReceiverSignature is string signature)
hists = hists.Where(hist => hist.Receiver!.Signature == signature);
return hists;
}, cancel);
}
}