using NSubstitute;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;

namespace ZB.MOM.WW.ScadaBridge.NotificationOutbox.Tests;

/// <summary>
/// Factory for the outbox repository substitute used across these tests.
/// </summary>
/// <remarks>
/// <see cref="INotificationOutboxRepository.UpdateAsync"/> returns whether the
/// targeted UPDATE actually matched a row — <c>false</c> is the "this
/// notification no longer exists" signal the operator retry/discard handlers
/// turn into a not-found reply. NSubstitute's default for <c>Task&lt;bool&gt;</c>
/// is <c>false</c>, i.e. the VANISHED-row answer, so an unconfigured substitute
/// would silently put every test on the failure path. Tests that want a healthy
/// store take one from here; the vanished-row tests configure
/// <c>Returns(false)</c> for themselves.
/// </remarks>
internal static class OutboxRepositorySubstitute
{
    /// <summary>Creates a substitute whose writes report that the row was found.</summary>
    public static INotificationOutboxRepository Healthy()
    {
        var repository = Substitute.For<INotificationOutboxRepository>();
        repository
            .UpdateAsync(Arg.Any<Notification>(), Arg.Any<CancellationToken>())
            .Returns(true);
        return repository;
    }
}
