import 'package:flutter/foundation.dart'; import 'server_catalog.dart'; /// Whether this device can use one saved machine right now. enum MachineAccess { /// Its connection is open, or its kept sign-in is accepted. connected, /// The machine wants its own password; no other machine's sign-in applies. needsPassword, /// Nothing answered, or what answered is not a Pipelines server. unreachable, } /// One access verdict with the sentence to show for it. class MachineAccessResult { const MachineAccessResult(this.access, {this.detail}); final MachineAccess access; final String? detail; bool get needsPassword => access == MachineAccess.needsPassword; bool get connected => access == MachineAccess.connected; } /// Authenticates saved machines independently of one another. Settings and /// the server editor use it to ask a new machine for its own password and to /// show each machine's live state; the chat pool implements it. abstract interface class MachineAuthenticator implements Listenable { /// The live verdict for a saved machine, null while it is still connecting /// or unknown to the pool. MachineAccessResult? status(String id); /// Asks [server] whether this device may use it without a new password. Future probe(SavedServer server); /// Signs in to [server] with its own password; null on success. Future authenticate(SavedServer server, String password); }