import Foundation

/// Represents a physical recording device bound to a user account via BLE.
struct BoundDevice: Codable, Identifiable, Equatable {
    let id: String           // CoreBluetooth peripheral identifier
    var name: String         // User-defined display name
    var peripheralUUID: String // CoreBluetooth Peripheral UUID
    var boundAt: Date        // Date when bound to user account
    var isConnected: Bool    // Connection status (runtime state)
    var batteryLevel: Int?   // Battery percentage (0 - 100)
    var firmwareVersion: String? // Firmware version
    var boundUserId: String  // User account ID owning this device
    var advertisedName: String? // Name reported in the BLE advertisement
    var hardwareMAC: String? // Hardware identity returned by PQ_BLE&MAC
    var freeStorageMB: Int?
    var totalStorageMB: Int?
    var cloudID: String?
    var cloudSyncError: String?
    
    init(
        id: String = UUID().uuidString,
        name: String,
        peripheralUUID: String = UUID().uuidString,
        boundAt: Date = Date(),
        isConnected: Bool = false,
        batteryLevel: Int? = 85,
        firmwareVersion: String? = "v1.2.0",
        boundUserId: String,
        advertisedName: String? = nil,
        hardwareMAC: String? = nil,
        freeStorageMB: Int? = nil,
        totalStorageMB: Int? = nil,
        cloudID: String? = nil,
        cloudSyncError: String? = nil
    ) {
        self.id = id
        self.name = name
        self.peripheralUUID = peripheralUUID
        self.boundAt = boundAt
        self.isConnected = isConnected
        self.batteryLevel = batteryLevel
        self.firmwareVersion = firmwareVersion
        self.boundUserId = boundUserId
        self.advertisedName = advertisedName
        self.hardwareMAC = hardwareMAC
        self.freeStorageMB = freeStorageMB
        self.totalStorageMB = totalStorageMB
        self.cloudID = cloudID
        self.cloudSyncError = cloudSyncError
    }
}

/// Helper structure for BLE scanning discovery results
struct DiscoveredBLEDevice: Identifiable, Equatable {
    let id: String
    let name: String
    let rssi: Int
    let peripheralUUID: String
}
