from src.analysis_functions.comparison_variance_in_and_between_group import (
    ComparisonVariance,
)
from src.data_classes.parameters_analysis_comparison_variance_in_and_between_group import (
    ComparisonVarianceInAndBetweenGroupParameters,
)
from src.utils.helper_logging import log_comparison_variance_details


def run_comparison_variance_in_and_between_group(
    comparison_variance: ComparisonVariance,
    analyses_list: list[ComparisonVarianceInAndBetweenGroupParameters],
):
    """
    Run a comparison between the mean variance in a variable grouped by a condition and the variance
    between group members based on a list of parameter objects.

    This function iterates over a list of ComparisonVarianceInAndBetweenGroupParameters objects,
    and then reports the total variance, variance between group members and mean variance of group members for
     each pair of variables specified in the ComparisonVarianceInAndBetweenGroupParameters object.

    Parameters
    ----------
    comparison_variance: ComparisonVariance
        An instance of the ComparisonVariance class.
    analyses_list: list[ComparisonVarianceInAndBetweenGroupParameters]
        A list of ComparisonVarianceInAndBetweenGroupParameters objects.
        Each object contains the parameters for a single variation comparison analysis.

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

        comparison_variance.compare_ingroup_intergroup_variance(
            data=analysis_config.data,
            variable=analysis_config.variable,
            group=analysis_config.group,
            name_save_file=analysis_config.name_save_file,
        )
