using Opc.Ua;
using ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters;

namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Fakes;

internal sealed class FakeEndpointDiscovery : IEndpointDiscovery
{
    public bool ThrowOnSelect { get; set; }
    public int SelectCallCount { get; private set; }
    public string? LastEndpointUrl { get; private set; }

    public EndpointDescription SelectEndpoint(ApplicationConfiguration config, string endpointUrl,
        MessageSecurityMode requestedMode)
    {
        SelectCallCount++;
        LastEndpointUrl = endpointUrl;

        if (ThrowOnSelect)
            throw new InvalidOperationException($"No endpoint found for {endpointUrl}");

        return new EndpointDescription
        {
            EndpointUrl = endpointUrl,
            SecurityMode = requestedMode,
            SecurityPolicyUri = requestedMode == MessageSecurityMode.None
                ? SecurityPolicies.None
                : SecurityPolicies.Basic256Sha256,
            Server = new ApplicationDescription
            {
                ApplicationName = "FakeServer",
                ApplicationUri = "urn:localhost:FakeServer"
            }
        };
    }
}