import pandas as pd
from statsmodels.regression.linear_model import RegressionResults

from src.analysis_functions.specific_analysis.get_function_inverse_bayes_transformed_regression import (
    get_function_inverse_bayes_transformed_regression,
)
from src.data_classes.parameters_analysis_get_function_inverse_bayes_transformed_regression import (
    GetFunctionInverseBayesTransformedRegressionParameters,
)
from src.utils.helper_functions import FunctionData
from src.utils.helper_logging import (
    log_get_function_inverse_bayes_transformed_regression,
)


def run_get_function_inverse_bayes_transformed_regression(
    analyses_list: list[GetFunctionInverseBayesTransformedRegressionParameters],
    regression_models: dict[str, RegressionResults],
) -> dict[str, FunctionData]:
    """
    Executes the inverse Bayes transformed regression analysis for a list of analysis configurations.

    This function iterates over a list of analysis configurations, logs the configuration details,
    performs the inverse Bayes transformed regression analysis using the specified regression model,
    and collects the results in a dictionary.

    Parameters
    ----------
    analyses_list : list[GetFunctionInverseBayesTransformedRegressionParameters]
        A list of parameters for each analysis to be run. Each item in the list is an instance
        of GetFunctionInverseBayesTransformedRegressionParameters, which includes the data and model name.
    regression_models : dict[str, RegressionResults]
        A dictionary mapping model names to their corresponding fitted regression models.

    Returns
    -------
    dict[str, FunctionData]
        A dictionary mapping the name of each analysis to its resulting FunctionData object.
    """
    functions: dict = {}

    for analysis_config in analyses_list:
        log_get_function_inverse_bayes_transformed_regression(analysis_config)

        function: FunctionData = get_function_inverse_bayes_transformed_regression(
            data=analysis_config.data,
            model=regression_models[analysis_config.model_name],
        )

        functions[analysis_config.name] = function

    return functions
