using Kompas.Mcp.Core.Drawings;

namespace Kompas.Mcp.Tests;

[Trait("Category", "Unit")]
public sealed class StampFieldsTests
{
    [Theory]
    [InlineData(StampField.Designation, 2)]
    [InlineData(StampField.Name, 1)]
    [InlineData(StampField.Material, 3)]
    public void ColumnId_maps_known_fields(StampField field, int expected)
        => Assert.Equal(expected, StampFields.ColumnId(field));

    [Fact]
    public void ColumnId_throws_on_unknown()
        => Assert.Throws<ArgumentOutOfRangeException>(() => StampFields.ColumnId((StampField)999));

    [Fact]
    public void Collect_skips_null_empty_and_whitespace()
        => Assert.Empty(StampFields.Collect(null, "", "   "));

    [Fact]
    public void Collect_trims_and_maps_provided_fields()
    {
        var result = StampFields.Collect("  ДЕТАЛЬ.001 ", null, "Сталь 45");

        Assert.Equal(2, result.Count);
        Assert.Contains(result, t => t.ColumnId == 2 && t.Text == "ДЕТАЛЬ.001"); // designation
        Assert.Contains(result, t => t.ColumnId == 3 && t.Text == "Сталь 45");   // material
        Assert.DoesNotContain(result, t => t.ColumnId == 1);                     // name не задан
    }

    [Fact]
    public void Collect_includes_name_as_column_1()
    {
        var result = StampFields.Collect(null, "Кронштейн", null);
        Assert.Single(result);
        Assert.Equal((1, "Кронштейн"), result[0]);
    }
}
