using System; using System.Threading; using System.Threading.Tasks; using HC_APTBS.Models; namespace HC_APTBS.Services { /// /// Manages the immobilizer unlock sequence required by certain pump ECUs /// (e.g. Ford VP44 models) before they respond to test commands. /// public interface IUnlockService { /// Raised with progress text during the unlock sequence. event Action? StatusChanged; /// Raised when the unlock sequence completes. Argument is true if successful. event Action? UnlockCompleted; /// /// Raised by the background observer on each lock→unlock transition. Unlike /// , this fires as soon as the CAN TestUnlock /// parameter confirms unlocked — regardless of whether the transition was /// caused by this service, an external manual unlock, or a fast-unlock /// completing early. Subscribers must marshal to the UI thread themselves. /// event Action? PumpUnlocked; /// /// Latched state from the background observer. True when the observer has /// verified the pump is unlocked; false when the observer is not running /// or the pump is currently locked. Use alongside /// to race-guard "was the event already fired?". /// bool IsPumpUnlocked { get; } /// /// Starts a 1-second polling observer that watches the CAN TestUnlock /// parameter and raises on each lock→unlock /// transition. Idempotent: stops any prior observer before starting the /// new one. No-op when is 0. /// void StartObserver(PumpDefinition pump); /// /// Stops the polling observer. Safe to call when no observer is active. /// Also resets to false. /// void StopObserver(); /// /// Runs the immobilizer unlock sequence for the given pump. /// Returns immediately if is 0 (no unlock needed). /// The persistent CAN senders remain active after this method returns; /// call when the pump is deselected. /// /// Pump definition with unlock type and CAN parameters. /// Cancellation token to abort the unlock sequence. Task UnlockAsync(PumpDefinition pump, CancellationToken ct); /// /// Stops the persistent CAN unlock senders. Call this when the pump is /// deselected or the application is shutting down. Safe to call when no /// senders are active. /// void StopSenders(); } }