"""
Configuration management for Holographic Memory
Handles all configuration methods and parameter validation
"""

import numpy as np
from typing import Dict, Any


class HolographicMemoryConfig:
    """Configuration manager for HolographicMemory system"""
    
    def __init__(self, memory_instance):
        self.memory = memory_instance
    
    def configure_binding_operation(self, operation_type: str = 'circular_convolution'):
        """Configure binding operation type for HRR"""
        valid_types = ['circular_convolution', 'matrix_multiplication', 'element_wise']
        if operation_type not in valid_types:
            raise ValueError(f"Invalid binding operation. Choose from: {valid_types}")
        
        self.memory.binding_operation = operation_type
        print(f"✓ Binding operation: {operation_type}")
        
    def configure_memory_model(self, model_type: str = 'distributed'):
        """Configure memory storage model"""
        valid_models = ['distributed', 'localized', 'hybrid']
        if model_type not in valid_models:
            raise ValueError(f"Invalid memory model. Choose from: {valid_models}")
        
        self.memory.memory_model = model_type
        print(f"✓ Memory model: {model_type}")
        
    def configure_cleanup_memory_type(self, cleanup_type: str = 'hopfield'):
        """Configure cleanup memory implementation"""
        valid_types = ['hopfield', 'kanerva', 'matrix']
        if cleanup_type not in valid_types:
            raise ValueError(f"Invalid cleanup type. Choose from: {valid_types}")
        
        self.memory.cleanup_memory_type = cleanup_type
        print(f"✓ Cleanup memory: {cleanup_type}")
        
    def configure_capacity_formula(self, formula_type: str = 'plate1995'):
        """Configure capacity calculation formula"""
        valid_formulas = ['plate1995', 'empirical', 'custom']
        if formula_type not in valid_formulas:
            raise ValueError(f"Invalid formula type. Choose from: {valid_formulas}")
        
        self.memory.capacity_formula = formula_type
        print(f"✓ Capacity formula: {formula_type}")
        
    def configure_trace_composition(self, composition_type: str = 'addition'):
        """Configure trace composition method"""
        valid_types = ['addition', 'binary_or', 'weighted']
        if composition_type not in valid_types:
            raise ValueError(f"Invalid composition type. Choose from: {valid_types}")
        
        self.memory.trace_composition = composition_type
        print(f"✓ Trace composition: {composition_type}")
        
    def configure_distributional_constraints(self, constraint_type: str = 'warn'):
        """Configure distributional constraint enforcement"""
        valid_types = ['enforce', 'warn', 'ignore']
        if constraint_type not in valid_types:
            raise ValueError(f"Invalid constraint type. Choose from: {valid_types}")
        
        self.memory.distributional_constraints = constraint_type
        print(f"✓ Distributional constraints: {constraint_type}")
        
    def configure_noncommutative_mode(self, enable: bool = False):
        """Configure noncommutative binding operations"""
        self.memory.noncommutative_mode = enable
        print(f"✓ Noncommutative mode: {'enabled' if enable else 'disabled'}")
        
    def configure_walsh_hadamard(self, enable: bool = False):
        """Configure Walsh-Hadamard transform optimization"""
        self.memory.walsh_hadamard = enable
        print(f"✓ Walsh-Hadamard optimization: {'enabled' if enable else 'disabled'}")
        
    def configure_sequence_encoding(self, encoding_type: str = 'positional'):
        """Configure sequence encoding strategy"""
        valid_types = ['positional', 'chaining', 'context']
        if encoding_type not in valid_types:
            raise ValueError(f"Invalid encoding type. Choose from: {valid_types}")
        
        self.memory.sequence_encoding = encoding_type
        print(f"✓ Sequence encoding: {encoding_type}")
        
    def configure_fast_cleanup(self, enable: bool = True):
        """Configure fast cleanup mode"""
        self.memory.fast_cleanup = enable
        print(f"✓ Fast cleanup: {'enabled' if enable else 'disabled'}")
        
    def configure_capacity_monitoring(self, enable: bool = True):
        """Configure capacity monitoring"""
        self.memory.capacity_monitoring = enable
        print(f"✓ Capacity monitoring: {'enabled' if enable else 'disabled'}")
        
    def configure_memory_compression(self, enable: bool = True):
        """Configure memory compression"""
        self.memory.memory_compression = enable
        print(f"✓ Memory compression: {'enabled' if enable else 'disabled'}")
        
    def configure_gpu_acceleration(self, enable: bool = False):
        """Configure GPU acceleration"""
        self.memory.gpu_acceleration = enable
        print(f"✓ GPU acceleration: {'enabled' if enable else 'disabled'}")