using ZB.MOM.WW.MxGateway.Client;
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;

namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Browse;

/// <summary>
///     Default <see cref="IGalaxyDeployWatchSource"/> wrapping the gateway's
///     <see cref="GalaxyRepositoryClient"/>. Forwards
///     <c>WatchDeployEventsAsync(lastSeenDeployTime, ct)</c> verbatim — paging /
///     bootstrap suppression policy lives on the gateway, while
///     <see cref="DeployWatcher"/> owns the change-detection and reconnect-loop
///     concerns above this seam.
/// </summary>
public sealed class GatewayGalaxyDeployWatchSource : IGalaxyDeployWatchSource
{
    private readonly GalaxyRepositoryClient _client;

    /// <summary>Initializes a new instance of the GatewayGalaxyDeployWatchSource class.</summary>
    /// <param name="client">The Galaxy repository client.</param>
    public GatewayGalaxyDeployWatchSource(GalaxyRepositoryClient client)
    {
        _client = client ?? throw new ArgumentNullException(nameof(client));
    }

    /// <inheritdoc />
    public IAsyncEnumerable<DeployEvent> WatchAsync(
        DateTimeOffset? lastSeenDeployTime, CancellationToken cancellationToken)
        => _client.WatchDeployEventsAsync(lastSeenDeployTime, cancellationToken);
}
