import Foundation

/// Stable per-install identifier — a UUID minted once on first access and kept
/// in UserDefaults for the life of the install. Distinct from the iCloud
/// account: two devices signed into the same account get different install IDs.
///
/// It answers "which device owns a pending transcription?" A voice note stamps
/// the recording device's `installID` into `AudioInfo.transcriberDeviceID`; only
/// the device whose `installID` matches transcribes it, while the others render
/// status only. Re-transcribing on any device reassigns the id to itself, which
/// is also the recovery path when the original recording device is gone.
enum InstallIdentity {
    private static let key = "Notes.installID"

    /// The per-install UUID, created lazily on first read and reused forever.
    static var installID: String {
        if let existing = UserDefaults.standard.string(forKey: key) {
            return existing
        }
        let fresh = UUID().uuidString
        UserDefaults.standard.set(fresh, forKey: key)
        return fresh
    }
}
