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

namespace ZB.MOM.WW.OtOpcUa.Driver.S7.IntegrationTests;

/// <summary>
///     Test helper bridging the v2 authoring shape (a typed <see cref="S7TagDefinition"/>) to the v3
///     delivery shape (<see cref="RawTagEntry"/>). Under v3 the driver no longer takes pre-declared
///     definitions — the deploy artifact hands it authored raw tags (RawPath + TagConfig blob), and the
///     driver rebuilds the typed definitions via <see cref="S7TagDefinitionFactory"/>. These integration
///     profiles keep expressing their intent as typed definitions; this helper serialises each back to its
///     TagConfig blob (via <see cref="S7TagDefinitionFactory.ToTagConfig"/>) and packages it as a
///     <see cref="RawTagEntry"/> whose RawPath is the def's <c>Name</c> — so the round-trip through the real
///     mapper reproduces the same definition the profile authored, keyed by the same name the
///     read/write/subscribe call sites use. Mirrors the unit-test project's helper of the same name.
/// </summary>
internal static class S7RawTags
{
    /// <summary>Serialises one typed definition into its <see cref="RawTagEntry"/> (RawPath = def.Name).</summary>
    /// <param name="def">The typed definition to convert.</param>
    /// <returns>The equivalent <see cref="RawTagEntry"/>.</returns>
    public static RawTagEntry Entry(S7TagDefinition def)
        => new(def.Name, S7TagDefinitionFactory.ToTagConfig(def), def.WriteIdempotent);

    /// <summary>Serialises a sequence of typed definitions into <see cref="RawTagEntry"/> records.</summary>
    /// <param name="defs">The typed definitions to convert.</param>
    /// <returns>The equivalent raw-tag entries.</returns>
    public static IReadOnlyList<RawTagEntry> Entries(params S7TagDefinition[] defs)
        => [.. defs.Select(Entry)];
}
