import json
import os

class PowerSavingConfigLoader:
    def __init__(self, config_file_path='power_saving_config.json'):
        self.config_file_path = config_file_path
        self.config = None
        self.load_config()

    def load_config(self):
        try:
            with open(self.config_file_path, 'r') as f:
                self.config = json.load(f)
        except FileNotFoundError:
            print(f"Error: Configuration file not found at {self.config_file_path}")
            self.config = self.create_default_config()
        except json.JSONDecodeError:
            print(f"Error: Invalid JSON in configuration file at {self.config_file_path}")
            self.config = self.create_default_config()

    def create_default_config(self):
        print("Creating default power saving configuration.")
        default_config = {
            "cpu_frequency_scaling": {
                "enabled": True,
                "governor": "powersave",
                "min_frequency": 800000,
                "max_frequency": 1600000
            },
            "display_dimming": {
                "enabled": True,
                "timeout": 120,
                "brightness_level": 50
            },
            "network_polling": {
                "interval": 300
            },
            "disk_spin_down": {
                "enabled": True,
                "idle_timeout": 600
            }
        }
        self.config = default_config
        return default_config

    def get_config(self):
        return self.config


if __name__ == '__main__':
    # Example Usage
    config_loader = PowerSavingConfigLoader()
    config = config_loader.get_config()
    print("Loaded Configuration:")
    print(config)
