using ZB.MOM.WW.HistorianGateway.Contracts.Grpc;
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway;
///
/// Abstraction over the HistorianGateway gRPC client surface consumed by the OtOpcUa historian
/// backend driver. Proto-typed (the wire contract lives in
/// ZB.MOM.WW.HistorianGateway.Contracts.Grpc); the concrete adapter wrapping
/// HistorianGatewayClient is supplied by a later task. The seam exists so the driver and
/// its tests can depend on a fake without a live gateway.
///
public interface IHistorianGatewayClient : IAsyncDisposable
{
/// Checks the tag catalog; false means explicitly absent, while failures propagate.
/// Historian tag name.
/// Cancellation token.
/// Whether the historian contains the tag.
Task TagExistsAsync(string tag, CancellationToken ct);
/// Streams raw historian samples for a tag over a time window.
/// The historian tag name to read.
/// Inclusive start of the requested time window (UTC).
/// Exclusive end of the requested time window (UTC).
/// The maximum number of raw samples to return.
/// Cancellation token.
/// An async stream of raw historian samples for the tag.
IAsyncEnumerable ReadRawAsync(
string tag,
DateTime startUtc,
DateTime endUtc,
int maxValues,
CancellationToken ct);
/// Streams aggregate samples for a tag using the given retrieval mode and interval.
/// The historian tag name to read.
/// Inclusive start of the requested time window (UTC).
/// Exclusive end of the requested time window (UTC).
/// The aggregate retrieval mode to apply.
/// The aggregation bucket interval.
/// Cancellation token.
/// An async stream of aggregate samples for the tag.
IAsyncEnumerable ReadAggregateAsync(
string tag,
DateTime startUtc,
DateTime endUtc,
RetrievalMode mode,
TimeSpan interval,
CancellationToken ct);
/// Reads the samples nearest to each of the requested timestamps (unary).
/// The historian tag name to read.
/// The timestamps (UTC) to find the nearest sample for.
/// Cancellation token.
/// The samples nearest to each requested timestamp.
Task> ReadAtTimeAsync(
string tag,
IReadOnlyList timestampsUtc,
CancellationToken ct);
/// Streams historian events over a window, optionally filtered to a single source name.
/// Optional source-name filter; null returns events from all sources.
/// Inclusive start of the time window (UTC).
/// Exclusive end of the time window (UTC).
///
/// Caps the number of events returned. The gateway wire contract (ReadEventsRequest) has
/// no per-call server cap, so this limit is enforced client-side by early stream termination:
/// 0 or negative means no client-side limit (the gateway may still apply its configured
/// RuntimeDb:EventReadMaxRows); a positive value stops draining after that many events.
///
/// Cancellation token.
/// An async stream of historian events within the window.
IAsyncEnumerable ReadEventsAsync(
string? sourceName,
DateTime startUtc,
DateTime endUtc,
int maxEvents,
CancellationToken ct);
/// Writes live values for a tag through the gateway's SQL live-write path.
/// The historian tag name to write values for.
/// The live values to write.
/// Cancellation token.
/// The write acknowledgement returned by the gateway.
Task WriteLiveValuesAsync(
string tag,
IReadOnlyList values,
CancellationToken ct);
/// Sends a single historian event.
/// The historian event to send.
/// Cancellation token.
/// The write acknowledgement returned by the gateway.
Task SendEventAsync(HistorianEvent evt, CancellationToken ct);
/// Ensures the supplied tag definitions exist (create-or-update).
/// The tag definitions to create or update.
/// Cancellation token.
/// Per-tag outcomes for the create-or-update operation.
Task EnsureTagsAsync(
IReadOnlyList definitions,
CancellationToken ct);
/// Probes gateway/historian reachability.
/// Cancellation token.
/// true when the gateway and historian are reachable; otherwise false.
Task ProbeAsync(CancellationToken ct);
/// Reads the gateway's current historian connection status.
/// Cancellation token.
/// The current connection status reported by the gateway.
Task GetConnectionStatusAsync(CancellationToken ct);
}