import Foundation nonisolated enum EnergyReadStatus: String, Codable, Sendable { case available, denied, gone, failed, identityChanged, deadline, unsupported, unverified } nonisolated enum EnergyCapability: String, Codable, Sendable { case verifiedCPU, unverified, unsupported, unavailable } nonisolated struct ProcessEnergyRequest: Codable, Sendable { let token: UUID let identities: [ProcessIdentity] static let limit = 256 static let byteLimit = 65_536 } nonisolated struct ProcessEnergyReading: Codable, Sendable { let id: ProcessIdentity let birth: UInt64 let uptime: TimeInterval let nanojoules: UInt64? let status: EnergyReadStatus } nonisolated struct ProcessEnergyReply: Codable, Sendable { let token: UUID let capability: EnergyCapability let readings: [ProcessEnergyReading] } nonisolated struct ProcessEnergyUsage: Identifiable, Sendable { let id: ProcessIdentity let watts: Double let seconds: TimeInterval } nonisolated struct ProcessEnergySnapshot: Sendable { enum State: Sendable { case waiting, available, partial, unavailable, unsupported } let date: Date let candidates: Int let readable: Int let rows: [ProcessEnergyUsage] // All valid measurements; no CPU prefilter. var measured: Int { rows.count } let state: State } nonisolated extension ProcessSnapshot { func withEnergy(_ energy: ProcessEnergySnapshot?) -> ProcessSnapshot { let values = Dictionary((energy?.rows ?? []).map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first }) return ProcessSnapshot(date: date, enumerated: enumerated, readable: readable, rows: rows.map { process in var row = process row.cpuPower = values[process.id]?.watts row.powerWindow = values[process.id]?.seconds return row }, failed: failed) } }