using Eis.Infrastructure.Security;

namespace Eis.Infrastructure.Tests.Security;

public sealed class DocumentVerificationCodeServiceTests
{
    private const string Secret = "test-document-verification-secret-32-characters";
    private readonly DocumentVerificationCodeService _codes = new(DocumentVerificationOptions.FromSecret(Secret));

    [Fact]
    public void ScoreReportCode_MatchesLegacyNodeImplementation()
    {
        var results = new[]
        {
            new ScoreSignatureItem("math", 118, "2026-07-20T08:00:00.000Z", null),
            new ScoreSignatureItem("chinese", 112, "2026-07-20T08:00:00.000Z", null)
        };

        var code = _codes.ScoreReportCode("registration_1", "candidate_1", "exam_1", results);
        var reordered = _codes.ScoreReportCode("registration_1", "candidate_1", "exam_1", results.Reverse());

        Assert.Equal("SR-38D987280CE4FBE78307B5F3", code);
        Assert.Equal(code, reordered);
        Assert.True(DocumentVerificationCodeService.SafeEquals(code, code.ToLowerInvariant()));
        Assert.False(DocumentVerificationCodeService.SafeEquals(code, $"{code}0"));
    }

    [Fact]
    public void AdmissionNoticeCode_MatchesLegacyNodeImplementation()
    {
        var code = _codes.AdmissionNoticeCode(
            "placement_1", "candidate_1", "school_1", "exam_1", "general",
            "AD01-EX-2026-000001", "2026-07-21T08:00:00.000Z");

        Assert.Equal("AN-E907684020E21579B854C167", code);
    }
}
