from src.analysis_functions.pearson_correlation import PearsonCorrelation
from src.data_classes.parameters_analysis_pearson_correlation import (
    PearsonCorrelationParameters,
)
from src.utils.helper_logging import log_pearson_correlation_details


def run_pearson_correlation(
    pearson_correlation: PearsonCorrelation,
    analyses_list: list[PearsonCorrelationParameters],
):
    """
    Run Pearson correlation analyses based on a list of parameter objects.

    This function iterates over a list of PearsonCorrelationParameters objects,
    and then calculates the Pearson correlation for each pair of variables specified
    in the PearsonCorrelationParameters object.

    Parameters
    ----------
    pearson_correlation: PearsonCorrelation
        An instance of the PearsonCorrelation class.
    analyses_list: list[PearsonCorrelationParameters
        A list of PearsonCorrelationParameters objects.
        Each object contains the parameters for a single Pearson correlation analysis.

    Returns
    -------
    None
    """
    for analysis_config in analyses_list:
        log_pearson_correlation_details(analysis_config)

        pearson_correlation.calculate_correlation(
            data=analysis_config.data,
            first_group_name=analysis_config.variable_1,
            second_group_name=analysis_config.variable_2,
            name_save_file=analysis_config.name_save_file,
        )
