using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace ZB.MOM.WW.LmxProxy.Host.Domain
{
///
/// Interface for SCADA system clients (MxAccess wrapper).
///
public interface IScadaClient : IAsyncDisposable
{
/// Gets whether the client is connected to MxAccess.
bool IsConnected { get; }
/// Gets the current connection state.
ConnectionState ConnectionState { get; }
/// Occurs when the connection state changes.
event EventHandler ConnectionStateChanged;
/// Connects to MxAccess.
Task ConnectAsync(CancellationToken ct = default);
/// Disconnects from MxAccess.
Task DisconnectAsync(CancellationToken ct = default);
/// Reads a single tag value.
/// VTQ with typed value.
Task ReadAsync(string address, CancellationToken ct = default);
/// Reads multiple tag values with semaphore-controlled concurrency.
/// Dictionary of address to VTQ.
Task> ReadBatchAsync(IEnumerable addresses, CancellationToken ct = default);
/// Writes a single tag value. Value is a native .NET type (not string).
Task WriteAsync(string address, object value, CancellationToken ct = default);
/// Writes multiple tag values with semaphore-controlled concurrency.
Task WriteBatchAsync(IReadOnlyDictionary values, CancellationToken ct = default);
///
/// Writes a batch of values, then polls flagTag until it equals flagValue or timeout expires.
/// Returns (writeSuccess, flagReached, elapsedMs).
///
/// Tag-value pairs to write.
/// Tag to poll after writes.
/// Expected value (type-aware comparison).
/// Max wait time in milliseconds.
/// Poll interval in milliseconds.
/// Cancellation token.
Task<(bool flagReached, int elapsedMs)> WriteBatchAndWaitAsync(
IReadOnlyDictionary values,
string flagTag,
object flagValue,
int timeoutMs,
int pollIntervalMs,
CancellationToken ct = default);
///
/// Probes connection health by reading a test tag.
/// Returns a classified result: Healthy, TransportFailure, or DataDegraded.
///
Task ProbeConnectionAsync(string testTagAddress, int timeoutMs, CancellationToken ct = default);
///
/// Unsubscribes specific tag addresses. Removes from stored subscriptions
/// and COM state. Safe to call after reconnect -- uses current handle mappings.
///
Task UnsubscribeByAddressAsync(IEnumerable addresses);
/// Subscribes to value changes for specified addresses.
/// Subscription handle for unsubscribing.
Task SubscribeAsync(
IEnumerable addresses,
Action callback,
CancellationToken ct = default);
}
}