using System;
using System.Threading;
using System.Threading.Tasks;
using HC_APTBS.Models;
namespace HC_APTBS.Services
{
///
/// Minimal host-side contract supplying runtime context that the
/// cannot derive on its own
/// (e.g. , which is owned by a ViewModel).
/// Implemented by MainViewModel.
///
public interface IAutoTestHost
{
/// Currently selected pump, if any.
PumpDefinition? CurrentPump { get; }
///
/// Ensures the oil-pump relay is energised before the auto-test proceeds.
///
/// - Returns true immediately if the pump is already on.
/// - When is true, silently
/// starts the pump and returns true.
/// - Otherwise, presents the leak-check confirmation dialog on the UI
/// thread. Returns true if the operator accepts (and the pump
/// is started), false if the operator cancels.
///
/// Safe to call from the orchestrator's background execution — the host
/// marshals to the UI thread internally.
///
Task EnsureOilPumpOnAsync(bool skipConfirmation);
}
///
/// Orchestrates the Dashboard "Connect & Auto Test" sequence.
///
/// Drives a linear state machine () that
/// connects the K-Line, reads the pump identification, runs the immobilizer
/// unlock (if required), energises the bench, starts the oil pump, and then
/// launches . Monitors liveness and
/// alarm transitions throughout so the sequence aborts safely on any failure,
/// requesting an emergency stop once the bench is energised.
///
public interface IAutoTestOrchestrator
{
/// Current state of the sequence.
AutoTestState State { get; }
///
/// Raised on every state transition. The optional detail argument
/// carries phase-specific information (progress percent, phase name, etc.).
/// Marshalling to the UI thread is the subscriber's responsibility.
///
event Action? StateChanged;
///
/// Raised once when the sequence aborts, before transitions
/// to .
///
event Action? Failed;
///
/// Runs the full auto-test sequence. Returns true on success,
/// false on any abort (failure reason is delivered via ).
///
Task RunAsync(CancellationToken ct);
///
/// Requests a cooperative cancellation of the in-flight sequence.
/// Safe to call when is .
///
void Cancel();
}
}