using RolemasterDb.ImportTool.Parsing;

namespace RolemasterDb.ImportTool.Tests;

public sealed class CriticalTableParserSupportTests
{
    [Theory]
    [InlineData("7-70", "67-70")]
    [InlineData("6-10", "06-10")]
    [InlineData("1-95", "91-95")]
    public void NormalizeRollBandLabel_repairs_known_ocr_missing_leading_digit_cases(string damagedLabel, string expectedLabel)
    {
        Assert.True(CriticalTableParserSupport.IsRollBandLabel(damagedLabel));
        Assert.Equal(expectedLabel, CriticalTableParserSupport.NormalizeRollBandLabel(damagedLabel));
    }

    [Fact]
    public void FindRowLabelFragments_keeps_repaired_ocr_row_labels_in_sequence()
    {
        List<PositionedTextFragment> fragments =
        [
            new PositionedTextFragment(1, 100, 10, 20, 10, "61-65"),
            new PositionedTextFragment(1, 120, 10, 20, 10, "7-70"),
            new PositionedTextFragment(1, 140, 10, 20, 10, "71-75")
        ];

        var rowLabelFragments = CriticalTableParserSupport.FindRowLabelFragments(fragments, leftCutoff: 100, bodyStartTop: 90, keyTop: 200);
        var labels = rowLabelFragments.Select(item => CriticalTableParserSupport.NormalizeRollBandLabel(item.Text)).ToList();

        Assert.Equal(["61-65", "67-70", "71-75"], labels);
    }
}