using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;

namespace ScadaLink.Communication.Tests;

/// <summary>
/// WP-2: Tests for CommunicationService initialization and state.
/// </summary>
public class CommunicationServiceTests
{
    [Fact]
    public async Task BeforeInitialization_ThrowsOnUsage()
    {
        var options = Options.Create(new CommunicationOptions());
        var logger = NullLogger<CommunicationService>.Instance;
        var service = new CommunicationService(options, logger);

        // CommunicationService requires SetCommunicationActor before use
        await Assert.ThrowsAsync<InvalidOperationException>(() =>
            service.DeployInstanceAsync("site1",
                new Commons.Messages.Deployment.DeployInstanceCommand(
                    "dep1", "inst1", "hash1", "{}", "admin", DateTimeOffset.UtcNow)));
    }

    [Fact]
    public void UnsubscribeDebugView_IsTellNotAsk()
    {
        // Verify the method signature is void (fire-and-forget Tell pattern)
        var method = typeof(CommunicationService).GetMethod("UnsubscribeDebugView");
        Assert.NotNull(method);
        Assert.Equal(typeof(void), method!.ReturnType);
    }
}
