using ZB.MOM.WW.OtOpcUa.Core.Abstractions;

namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests;

/// <summary>
///     Test helper bridging the pre-v3 pre-declared-tag authoring style (a typed
///     <see cref="AbCipTagDefinition"/>) to the v3 RawPath seam the driver now consumes
///     (<see cref="RawTagEntry"/>). Each typed def is serialised to its <c>TagConfig</c> blob via
///     <see cref="AbCipTagDefinitionFactory.ToTagConfig"/>, and the def's identity (<c>Name</c> → RawPath),
///     device routing key (<c>DeviceHostAddress</c> → <see cref="RawTagEntry.DeviceName"/>) and write-idempotence
///     travel on the entry — exactly the shape the deploy artifact delivers. Lets the driver's read / write /
///     discovery suites keep expressing fixtures as typed definitions while exercising the v3
///     <c>RawTags</c> → <c>FromTagConfig</c> table-build path.
/// </summary>
internal static class AbCipRawTags
{
    /// <summary>Projects typed definitions to the driver's <c>RawTags</c> option shape.</summary>
    /// <param name="defs">The typed definitions to project.</param>
    /// <returns>The equivalent <see cref="RawTagEntry"/> list.</returns>
    public static IReadOnlyList<RawTagEntry> From(params AbCipTagDefinition[] defs) =>
        [.. defs.Select(d => new RawTagEntry(
            RawPath: d.Name,
            TagConfig: AbCipTagDefinitionFactory.ToTagConfig(d),
            WriteIdempotent: d.WriteIdempotent,
            DeviceName: d.DeviceHostAddress))];
}
