import Foundation

/// The single plaintext frame a client sends *before* the Noise handshake, so the host can
/// route the connection to the right pattern (SYNC_PROTOCOL §4.2/§4.3). It carries no
/// secrets — just which handshake to run and who's claiming to connect. Everything after it
/// is encrypted.
///
/// - `.pair` → run `XXpsk0` with the QR pairing secret (first-time pairing, TOFU pin).
/// - `.reconnect` → run `IK` against the host static the device pinned at pairing; the host
///   then checks the peer's recovered static matches that device's pin (revocation gate).
public enum HandshakeMode: String, Sendable, Codable {
    case pair
    case reconnect
}

public struct HandshakePreamble: Sendable, Codable, Equatable {
    public let protocolVersion: Int
    public let mode: HandshakeMode
    public let deviceID: String

    public init(
        protocolVersion: Int = SyncProtocol.version,
        mode: HandshakeMode, deviceID: String
    ) {
        self.protocolVersion = protocolVersion
        self.mode = mode
        self.deviceID = deviceID
    }
}
