using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;

namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;

[Trait("Category", "Unit")]
public sealed class UnsTreeServiceEquipmentChildRowsTests
{
    private static UnsTreeService SeededService()
    {
        var dbName = $"uns-childrows-{Guid.NewGuid():N}";
        UnsTreeTestDb.SeedNamed(dbName);
        return new UnsTreeService(UnsTreeTestDb.Factory(dbName));
    }

    // v3 Batch-1: the equipment↔Tag binding was retired (Tag is Raw-only; authoring moved to the Raw
    // tree in Batch 2). LoadTagsForEquipmentAsync is a stub that always returns empty — no equipment
    // has bound driver tags to list. The former in-name-order / EquipmentId-scoping assertions moved
    // with the authoring surface to the Batch-2 Raw-tree tests.
    [Fact]
    public async Task LoadTagsForEquipment_returns_empty_stub()
    {
        var rows = await SeededService().LoadTagsForEquipmentAsync(UnsTreeTestDb.SeededEquipmentId);
        rows.ShouldBeEmpty();
    }

    [Fact]
    public async Task LoadVirtualTagsForEquipment_returns_vtags_in_name_order()
    {
        var rows = await SeededService().LoadVirtualTagsForEquipmentAsync(UnsTreeTestDb.SeededEquipmentId);
        rows.Count.ShouldBe(1);
        rows[0].VirtualTagId.ShouldBe("VTAG-1");
        rows[0].Name.ShouldBe("computed");
        rows[0].DataType.ShouldBe("Double");
    }

    [Fact]
    public async Task LoadTagsForEquipment_empty_for_unknown_equipment()
        => (await SeededService().LoadTagsForEquipmentAsync("EQ-NONE")).ShouldBeEmpty();
}
