using System.Reflection;
using AuditEvent = ZB.MOM.WW.Audit.AuditEvent;
using IAuditWriter = ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services.IAuditWriter;
using ICentralAuditWriter = ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services.ICentralAuditWriter;

namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Interfaces.Services;

/// <summary>
/// Reflection-level contract guards for the Audit Log (#23) writer interfaces.
/// Locks in method signature so DI bindings + adapter implementations stay aligned.
/// </summary>
public class AuditWriterContractTests
{
    [Theory]
    [InlineData(typeof(IAuditWriter))]
    [InlineData(typeof(ICentralAuditWriter))]
    public void WriteAsync_HasExpectedSignature(Type writerType)
    {
        var method = writerType.GetMethod("WriteAsync", BindingFlags.Instance | BindingFlags.Public);
        Assert.NotNull(method);
        Assert.Equal(typeof(Task), method!.ReturnType);

        var parameters = method.GetParameters();
        Assert.Equal(2, parameters.Length);
        Assert.Equal(typeof(AuditEvent), parameters[0].ParameterType);
        Assert.Equal(typeof(CancellationToken), parameters[1].ParameterType);
        Assert.True(parameters[1].HasDefaultValue);
    }

    [Fact]
    public void IAuditWriter_AndICentralAuditWriter_AreDistinctTypes()
    {
        Assert.NotEqual(typeof(IAuditWriter), typeof(ICentralAuditWriter));
        Assert.False(typeof(IAuditWriter).IsAssignableFrom(typeof(ICentralAuditWriter)));
        Assert.False(typeof(ICentralAuditWriter).IsAssignableFrom(typeof(IAuditWriter)));
    }
}
