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="IGalaxyHierarchySource"/> wrapping the gateway's
///     <see cref="GalaxyRepositoryClient"/>. Pages internally via the client's overload.
/// </summary>
public sealed class GatewayGalaxyHierarchySource : IGalaxyHierarchySource
{
    private readonly GalaxyRepositoryClient _client;

    /// <summary>
    ///     Initializes a new instance of the <see cref="GatewayGalaxyHierarchySource"/> class.
    /// </summary>
    /// <param name="client">The gateway's Galaxy repository client for discovering the object hierarchy.</param>
    public GatewayGalaxyHierarchySource(GalaxyRepositoryClient client)
    {
        _client = client ?? throw new ArgumentNullException(nameof(client));
    }

    /// <inheritdoc />
    public Task<IReadOnlyList<GalaxyObject>> GetHierarchyAsync(CancellationToken cancellationToken)
        => _client.DiscoverHierarchyAsync(cancellationToken);
}
