import Foundation

public struct SystemSnapshotReader: Sendable {
    private let thermalReader: ThermalSensorReader
    private let memoryReader: MemoryPressureReader

    public init(
        thermalReader: ThermalSensorReader = ThermalSensorReader(),
        memoryReader: MemoryPressureReader = MemoryPressureReader())
    {
        self.thermalReader = thermalReader
        self.memoryReader = memoryReader
    }

    public func read() -> SystemSnapshot {
        let thermal = self.thermalReader.readSummary()
        let memory = self.memoryReader.read()

        return SystemSnapshot(
            cpuTemperatureCelsius: thermal.cpuTemperatureCelsius,
            gpuTemperatureCelsius: thermal.gpuTemperatureCelsius,
            memoryPressureFraction: memory.fraction,
            memoryPressureLevel: memory.level,
            thermalState: SystemThermalState(ProcessInfo.processInfo.thermalState))
    }
}
