using Xunit;

namespace Shared.Excel.Tests;

public sealed class ImportMappingEngineTests
{
    private static readonly ImportDefinition Definition = new(
        "test.orders", "TEST-ORD-001", "order", "주문 Import",
        [
            new("itemCode", "품목코드", ["상품코드", "SKU"], "lookup", true),
            new("quantity", "수량", ["주문수량", "Qty"], "quantity", true),
        ], true, false);

    [Fact]
    public void Exact_label_has_priority()
    {
        var mapping = new ImportMappingEngine().Map(["품목코드", "수량"], Definition);
        Assert.Equal("itemCode", mapping[0].TargetField);
        Assert.Equal("exact", mapping[0].Source);
    }

    [Fact]
    public void Alias_is_resolved_without_ai()
    {
        var mapping = new ImportMappingEngine().Map(["SKU", "주문수량"], Definition);
        Assert.Equal("itemCode", mapping[0].TargetField);
        Assert.Equal("alias", mapping[0].Source);
        Assert.Equal("quantity", mapping[1].TargetField);
    }

    [Fact]
    public void Saved_mapping_wins_before_new_inference()
    {
        var saved = new[] { new ImportMapping("MySku", "itemCode", "manual") };
        var mapping = new ImportMappingEngine().Map(["MySku"], Definition, saved);
        Assert.Equal("itemCode", mapping[0].TargetField);
        Assert.Equal("saved", mapping[0].Source);
    }
}
