
import Foundation
import UIKit

final class FullPerformanceOptimizer {

    static let shared = FullPerformanceOptimizer()

    private(set) var isEnabled = false

    private(set) var settings: [String: Double] = [
        "memoryOptimization": 0.85,
        "cpuEfficiency": 0.80,
        "graphicsOptimization": 0.85,
        "frameStability": 0.90,
        "touchResponse": 0.85,
        "thermalProtection": 0.90,
        "backgroundControl": 0.80,
        "animationOptimization": 0.75
    ]

    func enable() {
        isEnabled = true
    }

    func disable() {
        isEnabled = false
    }

    func configure(
        memoryOptimization: Double,
        cpuEfficiency: Double,
        graphicsOptimization: Double,
        frameStability: Double,
        touchResponse: Double,
        thermalProtection: Double,
        backgroundControl: Double,
        animationOptimization: Double
    ) {
        settings["memoryOptimization"] = clamp(memoryOptimization)
        settings["cpuEfficiency"] = clamp(cpuEfficiency)
        settings["graphicsOptimization"] = clamp(graphicsOptimization)
        settings["frameStability"] = clamp(frameStability)
        settings["touchResponse"] = clamp(touchResponse)
        settings["thermalProtection"] = clamp(thermalProtection)
        settings["backgroundControl"] = clamp(backgroundControl)
        settings["animationOptimization"] = clamp(animationOptimization)
    }

    func getSettings() -> [String: Double] {
        return settings
    }

    func getThermalState() -> ProcessInfo.ThermalState {
        return ProcessInfo.processInfo.thermalState
    }

    private func clamp(_ value: Double) -> Double {
        return min(max(value, 0.0), 1.0)
    }
}
