using Grpc.Core;
using ZB.MOM.WW.MxGateway.Contracts.Proto;

namespace ZB.MOM.WW.MxGateway.Client;

internal interface IMxGatewayClientTransport
{
    /// <summary>
    /// Gets the client configuration options.
    /// </summary>
    MxGatewayClientOptions Options { get; }

    /// <summary>
    /// Gets the underlying gRPC client, if available.
    /// </summary>
    MxAccessGateway.MxAccessGatewayClient? RawClient { get; }

    /// <summary>
    /// Opens a new gateway session.
    /// </summary>
    /// <param name="request">Session open request.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>The session open reply.</returns>
    Task<OpenSessionReply> OpenSessionAsync(
        OpenSessionRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Closes an open gateway session.
    /// </summary>
    /// <param name="request">Session close request.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>The session close reply.</returns>
    Task<CloseSessionReply> CloseSessionAsync(
        CloseSessionRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Invokes an MXAccess command on the session.
    /// </summary>
    /// <param name="request">The command request.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>The command reply.</returns>
    Task<MxCommandReply> InvokeAsync(
        MxCommandRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Streams events from the session.
    /// </summary>
    /// <param name="request">The stream events request.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>An async enumerable of events.</returns>
    IAsyncEnumerable<MxEvent> StreamEventsAsync(
        StreamEventsRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Acknowledges an active MXAccess alarm condition.
    /// </summary>
    /// <param name="request">The acknowledge request.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>The acknowledge reply with native MxStatus.</returns>
    Task<AcknowledgeAlarmReply> AcknowledgeAlarmAsync(
        AcknowledgeAlarmRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Streams a snapshot of all alarms currently in Active or ActiveAcked state — the
    /// ConditionRefresh equivalent for the gateway.
    /// </summary>
    /// <param name="request">The query request, optionally scoped by alarm-reference prefix.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>An async enumerable of active-alarm snapshots.</returns>
    IAsyncEnumerable<ActiveAlarmSnapshot> QueryActiveAlarmsAsync(
        QueryActiveAlarmsRequest request,
        CallOptions callOptions);

    /// <summary>
    /// Attaches to the gateway's central alarm feed — the current active-alarm
    /// snapshot followed by live transitions.
    /// </summary>
    /// <param name="request">The stream request, optionally scoped by alarm-reference prefix.</param>
    /// <param name="callOptions">gRPC call options.</param>
    /// <returns>An async enumerable of alarm feed messages.</returns>
    IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
        StreamAlarmsRequest request,
        CallOptions callOptions);
}
