using System;
using StellaOps.Cryptography.Audit;

namespace StellaOps.Cryptography.Tests.Audit;

public class AuthEventRecordTests
{
    [Fact]
    public void AuthEventRecord_InitializesCollections()
    {
        var record = new AuthEventRecord
        {
            EventType = "authority.test",
            Outcome = AuthEventOutcome.Success
        };

        Assert.NotNull(record.Scopes);
        Assert.Empty(record.Scopes);
        Assert.NotNull(record.Properties);
        Assert.Empty(record.Properties);
    }

    [Fact]
    public void ClassifiedString_NormalizesWhitespace()
    {
        var value = ClassifiedString.Personal("   ");
        Assert.Null(value.Value);
        Assert.False(value.HasValue);
        Assert.Equal(AuthEventDataClassification.Personal, value.Classification);
    }

    [Fact]
    public void Subject_DefaultsToEmptyCollections()
    {
        var subject = new AuthEventSubject();
        Assert.NotNull(subject.Attributes);
        Assert.Empty(subject.Attributes);
    }

    [Fact]
    public void Record_AssignsTimestamp_WhenNotProvided()
    {
        var record = new AuthEventRecord
        {
            EventType = "authority.test",
            Outcome = AuthEventOutcome.Success
        };

        Assert.NotEqual(default, record.OccurredAt);
        Assert.InRange(
            record.OccurredAt,
            DateTimeOffset.UtcNow.AddSeconds(-5),
            DateTimeOffset.UtcNow.AddSeconds(5));
    }
}
