using ZB.MOM.WW.OtOpcUa.Commons.Browsing;

namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Browsing;

/// <summary>Test double for <see cref="IUniversalDriverBrowser"/>. CanBrowse is driven by a
/// predicate (default: never); OpenAsync delegates to a handler or returns a fresh session.</summary>
internal sealed class FakeUniversalDriverBrowser : IUniversalDriverBrowser
{
    /// <summary>CanBrowse gate. Defaults to "no universal affordance for any type".</summary>
    public Func<string, string, bool> CanBrowsePredicate { get; init; } = (_, _) => false;

    /// <summary>OpenAsync behavior. Defaults to a fresh FakeBrowseSession.</summary>
    public Func<string, string, CancellationToken, Task<IBrowseSession>> OpenHandler { get; init; } =
        (_, _, _) => Task.FromResult<IBrowseSession>(new FakeBrowseSession());

    public bool CanBrowse(string driverType, string configJson) => CanBrowsePredicate(driverType, configJson);

    public Task<IBrowseSession> OpenAsync(string driverType, string configJson, CancellationToken ct) =>
        OpenHandler(driverType, configJson, ct);
}
