using StellaOps.Scanner.Core.Utility;
using Xunit;

namespace StellaOps.Scanner.Core.Tests.Utility;

public sealed class ScannerIdentifiersTests
{
    [Fact]
    public void CreateJobId_IsDeterministicAndCaseInsensitive()
    {
        var first = ScannerIdentifiers.CreateJobId("registry.example.com/repo:latest", "SHA256:ABC", "Tenant-A", "salt");
        var second = ScannerIdentifiers.CreateJobId("REGISTRY.EXAMPLE.COM/REPO:latest", "sha256:abc", "tenant-a", "salt");

        Assert.Equal(first, second);
    }

    [Fact]
    public void CreateDeterministicHash_ProducesLowercaseHex()
    {
        var hash = ScannerIdentifiers.CreateDeterministicHash("scan", "abc", "123");

        Assert.Matches("^[0-9a-f]{64}$", hash);
        Assert.Equal(hash, hash.ToLowerInvariant());
    }

    [Fact]
    public void NormalizeImageReference_LowercasesRegistryAndRepository()
    {
        var normalized = ScannerIdentifiers.NormalizeImageReference("Registry.Example.com/StellaOps/Scanner:1.0");

        Assert.Equal("registry.example.com/stellaops/scanner:1.0", normalized);
    }
}
