from .lattice import LatticeQuantumWalk
from .graphs import run_chawla_ranking, run_szegedy_service, run_community_detection, run_quantum_pagerank, run_hadamard

def run_simulation(model: str, **kwargs):
    """
    Unified entry point for Quantum Walk simulations.
    
    Args:
        model (str): The type of simulation to run.
                     Options: '1d', '2d', '3d' (Lattice Walks)
                              'ChawlaQW' (Chawla Directed Ranking)
                              'QPageRank' (Quantum PageRank)
                              'HadamardQW' (Hadamard Edge Importance)
                              'SzegedyQW' (Szegedy Walk)
                              'directSumQW' (Direct Sum Quantum Walk)
        **kwargs: Parameters specific to the chosen model.
    """
    model_upper = model
    
    # Lattice Walks
    if model_upper in ['1d', '2d', '3d']:
        dim_map = {'1d': 1, '2d': 2, '3d': 3}
        dimension = dim_map[model_upper]
        network_size = kwargs.get('network_size', 100 if dimension==1 else 20 if dimension==2 else 25)
        steps = kwargs.get('steps', 100)
        initial_dist = kwargs.get('initial_dist', 'uniform')
        compare_classical = kwargs.get('compare_classical', False)
        if dimension in [1, 2] and 'compare_classical' not in kwargs: compare_classical = True
        
        qw = LatticeQuantumWalk(dimension=dimension, network_size=network_size)
        qw.run(steps=steps, initial_dist=initial_dist, compare_classical=compare_classical)
        qw.visualize()
        return qw.results

    # Graph Walks
    elif model_upper == 'ChawlaQW':
        return run_chawla_ranking(file_path=kwargs.get('file_path'), 
                                  steps=kwargs.get('steps', 100), 
                                  coin_type=kwargs.get('coin_type', 'fourier'))
    
    elif model_upper == 'SzegedyQW':
        return run_szegedy_service(G=kwargs.get('G'),
                                   steps=kwargs.get('steps', 10),
                                   initial_type=kwargs.get('initial_type', 'uniform'),
                                   initial_node=kwargs.get('initial_node'))

    elif model_upper == 'QPageRank':
        return run_quantum_pagerank(file_path=kwargs.get('file_path'),
                                    steps=kwargs.get('steps', 20),
                                    alpha=kwargs.get('alpha', 0.85),
                                    initial_type=kwargs.get('initial_type', 'uniform'))
                                    
    elif model_upper == 'HadamardQW':
        return run_hadamard(steps=kwargs.get('steps', 100),
                            top_p=kwargs.get('top_p', 0.05))
    
    elif model_upper == 'directSumQW':
        #  directSumQW 
        return run_community_detection(G=kwargs.get('G'),
                                       initial_state=kwargs.get('initial_state', 'uniform'),
                                       coin_type=kwargs.get('coin_type', 'fourier'))
    
    else:
        available_models = ['1d', '2d', '3d', 'ChawlaQW', 'QPageRank', 'HadamardQW', 'SzegedyQW', 'directSumQW']
        raise ValueError(f"Unknown model type: {model}. Available: {', '.join(available_models)}")
