using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Shared.Contracts;

namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Host.Backend;

/// <summary>
///     Galaxy data-plane abstraction. Replaces the placeholder <c>StubFrameHandler</c> with a
///     real boundary the lifted <c>MxAccessClient</c> + <c>GalaxyRepository</c> implement during
///     Phase 2 Task B.1. Splitting the IPC dispatch (<c>GalaxyFrameHandler</c>) from the
///     backend means the dispatcher is unit-testable against an in-memory mock without needing
///     live Galaxy.
/// </summary>
public interface IGalaxyBackend
{
    /// <summary>
    ///     Server-pushed events the backend raises asynchronously (data-change, alarm,
    ///     host-status). The frame handler subscribes once on connect and forwards each
    ///     event to the Proxy as a typed <see cref="MessageKind"/> notification.
    /// </summary>
    event System.EventHandler<OnDataChangeNotification>? OnDataChange;
    event System.EventHandler<GalaxyAlarmEvent>? OnAlarmEvent;
    event System.EventHandler<HostConnectivityStatus>? OnHostStatusChanged;

    Task<OpenSessionResponse> OpenSessionAsync(OpenSessionRequest req, CancellationToken ct);
    Task CloseSessionAsync(CloseSessionRequest req, CancellationToken ct);

    Task<DiscoverHierarchyResponse> DiscoverAsync(DiscoverHierarchyRequest req, CancellationToken ct);

    Task<ReadValuesResponse> ReadValuesAsync(ReadValuesRequest req, CancellationToken ct);
    Task<WriteValuesResponse> WriteValuesAsync(WriteValuesRequest req, CancellationToken ct);

    Task<SubscribeResponse> SubscribeAsync(SubscribeRequest req, CancellationToken ct);
    Task UnsubscribeAsync(UnsubscribeRequest req, CancellationToken ct);

    Task SubscribeAlarmsAsync(AlarmSubscribeRequest req, CancellationToken ct);
    Task AcknowledgeAlarmAsync(AlarmAckRequest req, CancellationToken ct);

    Task<HistoryReadResponse> HistoryReadAsync(HistoryReadRequest req, CancellationToken ct);
    Task<HistoryReadProcessedResponse> HistoryReadProcessedAsync(HistoryReadProcessedRequest req, CancellationToken ct);
    Task<HistoryReadAtTimeResponse> HistoryReadAtTimeAsync(HistoryReadAtTimeRequest req, CancellationToken ct);
    Task<HistoryReadEventsResponse> HistoryReadEventsAsync(HistoryReadEventsRequest req, CancellationToken ct);

    Task<RecycleStatusResponse> RecycleAsync(RecycleHostRequest req, CancellationToken ct);
}
