import yaml
import os

class ScalingManager:
    def __init__(self, config_path='config/aiva_config.yaml'):
        self.config = self.load_config(config_path)
        self.enable_email_notifications = self.config.get('enable_email_notifications', True)

    def load_config(self, config_path):
        try:
            with open(config_path, 'r') as f:
                return yaml.safe_load(f)
        except FileNotFoundError:
            print(f"Warning: Configuration file not found at {config_path}. Using default settings.")
            return {}

    def scale_up(self):
        print("Scaling up...")
        if self.enable_email_notifications:
            self.send_email("Scaling up event occurred!")

    def scale_down(self):
        print("Scaling down...")
        if self.enable_email_notifications:
            self.send_email("Scaling down event occurred!")

    def send_email(self, message):
        print(f"Sending email: {message}")  # Placeholder for actual email sending logic

# Example usage (for testing):
if __name__ == '__main__':
    scaling_manager = ScalingManager()
    scaling_manager.scale_up()
    scaling_manager.scale_down()

    # Example with email notifications disabled:
    config_path = 'config/aiva_config.yaml'
    with open(config_path, 'w') as f:
        yaml.dump({'enable_email_notifications': False}, f)

    scaling_manager_disabled = ScalingManager()
    scaling_manager_disabled.scale_up()
    scaling_manager_disabled.scale_down()

    # Restore config
    with open(config_path, 'w') as f:
        yaml.dump({'enable_email_notifications': True}, f)
