using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;

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

/// <summary>
/// v3 Batch-1 migration: the per-equipment candidate-driver loader
/// (<see cref="UnsTreeService.LoadTagDriversForEquipmentAsync"/>) is RETIRED. The equipment↔driver
/// binding and the <c>Namespace</c>/<c>NamespaceKind</c> entities were deleted — equipment no longer
/// scopes a candidate-driver list, and per-driver-typed tag authoring moved to the Raw tree (/raw) in
/// Batch 2. The loader now always returns empty; the former "surfaces DriverType/DriverConfig" test
/// (which fed the TagModal editor dispatch + Galaxy live-browse picker) is replaced by the stub
/// assertion below. That editor-dispatch coverage is re-established under the Batch-2 Raw-tree tests.
/// </summary>
[Trait("Category", "Unit")]
public sealed class UnsTreeServiceTagDriversTests
{
    /// <summary>The retired loader returns empty even when a matching cluster driver exists.</summary>
    [Fact]
    public async Task LoadTagDriversForEquipment_returns_empty_stub()
    {
        var dbName = $"uns-tagdrivers-{Guid.NewGuid():N}";

        using (var db = UnsTreeTestDb.CreateNamed(dbName))
        {
            db.ServerClusters.Add(new ServerCluster
            {
                ClusterId = "MAIN",
                Name = "Main",
                Enterprise = "zb",
                Site = "warsaw-west",
                RedundancyMode = RedundancyMode.None,
                CreatedBy = "test",
            });
            db.UnsAreas.Add(new UnsArea { UnsAreaId = "AREA-1", ClusterId = "MAIN", Name = "a" });
            db.UnsLines.Add(new UnsLine { UnsLineId = "LINE-1", UnsAreaId = "AREA-1", Name = "l" });
            db.Equipment.Add(new Equipment
            {
                EquipmentId = "EQ-1",
                EquipmentUuid = Guid.NewGuid(),
                UnsLineId = "LINE-1",
                Name = "machine-1",
                MachineCode = "machine_001",
            });
            db.DriverInstances.Add(new DriverInstance
            {
                DriverInstanceId = "DRV-EQ",
                ClusterId = "MAIN",
                Name = "equipment driver",
                DriverType = "Modbus",
                DriverConfig = """{"endpoint":"10.0.0.1:502"}""",
            });
            db.SaveChanges();
        }

        var service = new UnsTreeService(UnsTreeTestDb.Factory(dbName));

        var drivers = await service.LoadTagDriversForEquipmentAsync("EQ-1");

        drivers.ShouldBeEmpty();
    }
}
