import Foundation

/// The build/release channel a peer was cut from, exchanged in the `hello`/`welcome`
/// handshake so a phone and Mac refuse to pair across incompatible channels (e.g. a beta
/// remote driving a stable desktop). The wire mirror of both apps' local `BuildChannel`
/// enums — those live in the app targets (which own the compile-time `NUCLEIC_*` defines);
/// this is the transport-agnostic projection each side maps into.
public enum ReleaseChannel: String, Sendable, Codable, Equatable {
    case local            // dev / locally-built
    case canary           // bleeding-edge distributed channel
    case beta             // public beta
    case releaseCandidate = "rc"
    case release          // stable / App Store

    /// Whether a peer on `other` may connect to a peer on `self`. Channels must match, with
    /// one deliberate exception: a canary build may connect to a local dev build (and vice
    /// versa), so a developer running a local desktop can drive it from a canary remote and
    /// canary testers can point at a local desktop. No other cross-channel pairing is allowed.
    public func isCompatible(with other: ReleaseChannel) -> Bool {
        if self == other { return true }
        let devInterchangeable: Set<ReleaseChannel> = [.local, .canary]
        return devInterchangeable.contains(self) && devInterchangeable.contains(other)
    }
}
