import Foundation
import UIKit

/// 设备 ID 工具：生成并持久化本机设备标识（对应 Android 端 DeviceUtils）。
/// 格式: CTRL-XXXXXXXX（8 位大写十六进制）
enum DeviceUtils {

    private static let key = "com.ttstd.webrtccontroller.deviceId"

    static func deviceId() -> String {
        let defaults = UserDefaults.standard
        if let saved = defaults.string(forKey: key), !saved.isEmpty {
            return saved
        }
        let seed = UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString
        let suffix = seed.replacingOccurrences(of: "-", with: "").prefix(8).uppercased()
        let id = "CTRL-\(suffix)"
        defaults.set(id, forKey: key)
        return id
    }
}
