namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;

/// <summary>
///     Wire-layer abstraction over a single PCCC tag. Mirrors <c>IAbCipTagRuntime</c>'s shape so
///     the same test-fake pattern applies; the only meaningful difference is the protocol layer
///     underneath (<c>ab_pccc</c> vs <c>ab_eip</c>).
/// </summary>
public interface IAbLegacyTagRuntime : IDisposable
{
    /// <summary>Initializes the tag runtime.</summary>
    /// <param name="cancellationToken">Cancellation token for the operation.</param>
    Task InitializeAsync(CancellationToken cancellationToken);

    /// <summary>Reads the current value of the tag.</summary>
    /// <param name="cancellationToken">Cancellation token for the operation.</param>
    Task ReadAsync(CancellationToken cancellationToken);

    /// <summary>Writes the encoded value to the tag.</summary>
    /// <param name="cancellationToken">Cancellation token for the operation.</param>
    Task WriteAsync(CancellationToken cancellationToken);

    /// <summary>Gets the current status of the tag operation.</summary>
    int GetStatus();

    /// <summary>Decodes the tag value according to the specified data type.</summary>
    /// <param name="type">The data type to decode.</param>
    /// <param name="bitIndex">Optional bit index for bit-level access.</param>
    object? DecodeValue(AbLegacyDataType type, int? bitIndex);

    /// <summary>Encodes a value for writing to the tag.</summary>
    /// <param name="type">The data type to encode.</param>
    /// <param name="bitIndex">Optional bit index for bit-level access.</param>
    /// <param name="value">The value to encode.</param>
    void EncodeValue(AbLegacyDataType type, int? bitIndex, object? value);
}

public interface IAbLegacyTagFactory
{
    /// <summary>Creates a tag runtime instance with the specified parameters.</summary>
    /// <param name="createParams">The tag creation parameters.</param>
    IAbLegacyTagRuntime Create(AbLegacyTagCreateParams createParams);
}

public sealed record AbLegacyTagCreateParams(
    string Gateway,
    int Port,
    string CipPath,
    string LibplctagPlcAttribute,
    string TagName,
    TimeSpan Timeout);
