using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Worker.Sta;
namespace ZB.MOM.WW.MxGateway.Worker.MxAccess;
///
/// Manages the runtime session between the worker and the MXAccess COM instance on an STA thread.
///
public interface IWorkerRuntimeSession : IDisposable
{
///
/// Starts the session, creates the MXAccess COM object, and returns ready metadata.
///
/// Identifier of the session.
/// ID of the worker process.
/// Token to cancel the asynchronous operation.
/// Asynchronous task returning worker readiness metadata.
Task StartAsync(
string sessionId,
int workerProcessId,
CancellationToken cancellationToken = default);
///
/// Dispatches an STA command to the MXAccess runtime and returns the reply.
///
/// STA command to execute on the STA thread.
/// Asynchronous task returning the command reply.
Task DispatchAsync(StaCommand command);
///
/// Captures a heartbeat snapshot of the runtime state.
///
WorkerRuntimeHeartbeatSnapshot CaptureHeartbeat();
///
/// Drains up to the specified number of pending events from the queue.
///
/// Maximum number of events to drain.
/// List of drained events.
IReadOnlyList DrainEvents(uint maxEvents);
///
/// Drains a pending fault from the queue, if any.
///
WorkerFault? DrainFault();
///
/// Cancels a pending command by correlation ID.
///
/// Correlation ID of the command to cancel.
/// True if the command was found and cancelled; otherwise, false.
bool CancelCommand(string correlationId);
///
/// Requests a graceful shutdown of the session.
///
void RequestShutdown();
///
/// Shuts down the session gracefully within the specified timeout.
///
/// Maximum time to allow for graceful shutdown.
/// Token to cancel the asynchronous operation.
/// Asynchronous task returning the shutdown result.
Task ShutdownGracefullyAsync(
TimeSpan timeout,
CancellationToken cancellationToken = default);
}