from src.analysis_functions.ttest import TTest
from src.data_classes.parameters_analysis_ttest import (
    TTestParameters,
    PairedTTestParameters,
)
from src.utils.helper_logging import log_ttest_details


def run_ttest(
    ttest: TTest, analyses_list: list[TTestParameters]
) -> dict[str, tuple[float, float, float]]:
    """
    Run t-test analyses based on a list of parameter objects.

    This function iterates over a list of TTestParameters objects,
    logs the details of each analysis, and then performs the appropriate
    t-test analysis based on the type of the TTestParameters object.

    Parameters
    ----------
    ttest: TTest
        An instance of the TTest class.
    analyses_list: list[TTestParameters]
        A list of TTestParameters objects.
        Each object contains the parameters for a single t-test analysis.

    Returns
    -------
    dict[str, tuple[float, float, float]]
    """
    ttest_results: dict = {}

    for analysis_config in analyses_list:
        result = None

        if isinstance(analysis_config, PairedTTestParameters):
            log_ttest_details(analysis_config, "Paired")

            result = ttest.perform_paired_ttest(
                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,
            )

        else:
            log_ttest_details(analysis_config, "")
            ttest.perform_ttest(
                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,
            )

        ttest_results[analysis_config.name] = result

    return ttest_results
