import logging

from src.data_classes.parameters_analysis_regression import (
    LinearRegressionParameters,
    BayesianRegressionParameters,
    GroupedLinearRegressionParameters,
)
from src.data_classes.parameters_descriptive_aggregated import (
    DescriptiveAggregatedParameters,
)
from src.data_classes.parameters_descriptive_overview import (
    DescriptiveOverviewParameters,
)
from src.data_classes.parameters_descriptive_percentage_of_dataset_under_condition import (
    DescriptivePercentageOfDatasetUnderConditionParameters,
)
from src.data_classes.parameters_plot_barchart import BarChartPlotParameters
from src.data_classes.parameters_plot_boxplot import BoxPlotParameters
from src.data_classes.parameters_plot_contourplot import ContourPlotParameters
from src.data_classes.parameters_plot_count_distribution import (
    CountDistributionPlotParameters,
)
from src.data_classes.parameters_plot_densityplot import DensityPlotParameters
from src.data_classes.parameters_plot_forestplot import ForestPlotParameters
from src.data_classes.parameters_plot_forestplot_paired_ttest import (
    ForestPlotPairedTTestParameters,
)
from src.data_classes.parameters_plot_grouped_histogram import (
    GroupedHistogramParameters,
)
from src.data_classes.parameters_plot_heatmap import HeatmapParameters
from src.data_classes.parameters_plot_hexbinplot import HexbinPlotParameters
from src.data_classes.parameters_plot_histogram import HistogramPlotParameters
from src.data_classes.parameters_plot_percentage_stacked_barchart import (
    PercentageStackedBarChartPlotParameters,
)
from src.data_classes.parameters_plot_ridgelineplot import RidgelineParameters
from src.data_classes.parameters_plot_simple_scatterplot import (
    SimpleScatterPlotParameters,
)
from src.data_classes.parameters_plot_stacked_barchart import (
    StackedBarChartPlotParameters,
)
from src.data_classes.parameters_plot_surfaceplot import SurfacePlotParameters
from src.data_classes.parameters_plot_violinplot import ViolinPlotParameters


def log_descriptive_analysis_details(config):
    logging.info(f"Descriptive Analysis: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Data: {config.dataset}")
    if isinstance(config, DescriptiveAggregatedParameters):
        logging.info(f"Variables: {config.variables}")
        logging.info(f"Aggregation Function: {config.aggregation_function}")
        logging.info(f"Group By: {config.group_by}")
    elif isinstance(config, DescriptiveOverviewParameters):
        logging.info(f"Metrics: {config.metrics}")
        logging.info(f"Group By: {config.group_by}")
    elif isinstance(config, DescriptivePercentageOfDatasetUnderConditionParameters):
        logging.info(f"Variable: {config.variable}")
        logging.info(f"Comparison: {config.comparison}")
        logging.info(f"Condition: {config.condition}")
    else:
        raise ValueError(
            f"Invalid type of descriptive analysis requested {type(config)}"
        )
    logging.info("```")


def log_regression_details(config, regression_type: str):
    logging.info(f"{regression_type} Regression Analysis: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Independent Variables: {config.independent_variables}")
    logging.info(f"Dependent Variable: {config.dependent_variable}")
    logging.info(f"Data: {config.dataset}")
    if isinstance(config, LinearRegressionParameters):
        logging.info(f"Standardize: {config.standardize}")
        logging.info(f"Report effect size: {config.report_effect_size}")
    elif isinstance(config, BayesianRegressionParameters):
        pass
    elif isinstance(config, GroupedLinearRegressionParameters):
        logging.info(f"Independent Variables: {config.independent_variables}")
        logging.info(f"Grouped by: {config.group_by}")
        logging.info(f"Aggregation methods: {config.dictionary_aggregation_methods}")
        logging.info(f"Standardize: {config.standardize}")
        logging.info(f"Report effect size: {config.report_effect_size}")
        logging.info(
            f"Print detailed coefficients: {config.print_detailed_coefficients}"
        )
    else:
        raise ValueError(f"Unknown parameter type: {type(config)}")

    logging.info("```")


def log_get_function_inverse_bayes_transformed_regression(config):
    logging.info(
        f"Get Function Inverse Bayes Transformed Regression: {config.name_save_file}"
    )
    logging.info("```")
    logging.info(f"Data: {config.data}")
    logging.info(f"Model Name: {config.model_name}")
    logging.info("```")


def log_influence_of_up_and_downvotes_on_replies(config):
    logging.info(f"Influence of Up and Downvotes on Replies: {config.name_save_file}")
    logging.info("```")
    logging.info(
        f"Weight as Distribution Quantile: {config.weight_as_distribution_quantile}"
    )
    logging.info(f"Weight m: {config.weight_m}")
    logging.info(f"Model Name: {config.model_name}")
    logging.info(f"Step: {config.step}")
    logging.info(f"Startpoint: {config.startpoint}")
    logging.info("```")


def log_comparison_variance_details(config):
    logging.info(f"Comparison Variance Analysis: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Variable: {config.variable}")
    logging.info(f"Group: {config.group}")
    logging.info(f"Data: {config.data}")
    logging.info("```")


def log_pearson_correlation_details(config):
    logging.info(f"Pearson Correlation Analysis: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Variable 1: {config.variable_1}")
    logging.info(f"Variable 2: {config.variable_2}")
    logging.info(f"Data: {config.dataset}")
    logging.info("```")


def log_ttest_details(config, ttest_type: str):
    logging.info(f"{ttest_type} TTest Analysis: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Variable 1: {config.variable_1}")
    logging.info(f"Variable 2: {config.variable_2}")
    logging.info(f"Data: {config.dataset}")
    logging.info("```")


def log_visualization_details(config):
    logging.info(f"Visualization: {config.name_save_file}")
    logging.info("```")
    logging.info(f"Data: {config.dataset}")
    logging.info(f"Title: {config.title}")
    if isinstance(config, BarChartPlotParameters):
        logging.info("Creating Bar Chart")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"Chart Orientation: {config.chart_orientation}")
        logging.info(f"Sort Order: {config.sort_order}")
    elif isinstance(config, BoxPlotParameters):
        logging.info("Creating Box Plot")
        logging.info(f"Variable 1: {config.variable_1}")
        logging.info(f"Variable 2: {config.variable_2}")
        logging.info(f"X-Axis Label: {config.x_axis_label}")
        logging.info(f"Y-Axis Label: {config.y_axis_label}")
    elif isinstance(config, ContourPlotParameters):
        logging.info("Creating Contour Plot")
        logging.info(f"Function Name: {config.function_name}")
        logging.info(f"X-Axis Maximum: {config.x_axis_maximum}")
        logging.info(f"Y-Axis Maximum: {config.y_axis_maximum}")
    elif isinstance(config, HistogramPlotParameters):
        logging.info("Creating Histogram Plot")
        logging.info(f"Variable: {config.variable}")
        logging.info(f"X-Axis Limits: {config.x_axis_limits}")
        logging.info(f"X-Axis Logarithmic Scaling: {config.x_axis_logarithmic_scaling}")
        logging.info(f"Y-Axis Logarithmic Scaling: {config.y_axis_logarithmic_scaling}")
    elif isinstance(config, CountDistributionPlotParameters):
        logging.info("Creating Count Distribution Plot")
        logging.info(f"Variable: {config.variable}")
        logging.info(f"X-Axis Limits: {config.x_axis_limits}")
        logging.info(f"X-Axis Logarithmic Scaling: {config.x_axis_logarithmic_scaling}")
        logging.info(f"Y-Axis Logarithmic Scaling: {config.y_axis_logarithmic_scaling}")
    elif isinstance(config, DensityPlotParameters):
        logging.info("Creating Density Plot")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"Data Breakpoints: {config.data_breakpoints}")
    elif isinstance(config, ForestPlotParameters):
        logging.info("Creating Forest Plot")
        logging.info(f"Regression Model Names: {config.regression_model_names}")
        logging.info(f"Coefficient Names: {config.coefficient_names}")
        logging.info(f"X-Axis Minimum: {config.x_axis_minimum}")
        logging.info(f"X-Axis Maximum: {config.x_axis_maximum}")
        logging.info(f"Dotsize: {config.dotsize}")
    elif isinstance(config, ForestPlotPairedTTestParameters):
        logging.info("Creating Forest Plot Paired TTest")
        logging.info(f"Paired TTest Names: {config.paired_ttest_names}")
        logging.info(f"X-Axis Minimum: {config.x_axis_minimum}")
        logging.info(f"X-Axis Maximum: {config.x_axis_maximum}")
        logging.info(f"Dotsize: {config.dotsize}")
    elif isinstance(config, GroupedHistogramParameters):
        logging.info("Creating Grouped Histogram")
        logging.info(f"Group By: {config.group_by}")
        logging.info(f"Aggregation Variable: {config.aggregation_variable}")
        logging.info(f"Aggregation Function: {config.aggregation_function}")
        logging.info(f"X-Axis Label: {config.x_axis_label}")
        logging.info(f"Y-Axis Label: {config.y_axis_label}")
    elif isinstance(config, HeatmapParameters):
        logging.info("Creating Heatmap")
        logging.info(f"Axis Variables: {config.axis_variables}")
        logging.info(f"Heat Variable: {config.heat_variable}")
        logging.info(f"Max Axis Values: {config.axis_maxima}")
        logging.info(f"Min Axis Values: {config.axis_minima}")
        logging.info(f"Log Scaling: {config.logarithmic_heat_scaling}")
    elif isinstance(config, HexbinPlotParameters):
        logging.info("Creating Hexbin Plot")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"X Axis Maximum: {config.x_axis_maximum}")
        logging.info(f"Y Axis Maximum: {config.y_axis_maximum}")
        logging.info(f"Trendline: {config.trendline}")
        logging.info(f"Log Scaling: {config.logarithmic_hex_scaling}")
    elif isinstance(config, PercentageStackedBarChartPlotParameters):
        logging.info("Creating Percentage Stacked Bar Chart")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variables to compare: {config.variables_to_compare}")
        logging.info(f"Chart Orientation: {config.chart_orientation}")
        logging.info(f"Sort Order: {config.sort_order}")
    elif isinstance(config, RidgelineParameters):
        logging.info("Creating Ridgeline Plot")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"Data Breakpoints: {config.data_breakpoints}")
    elif isinstance(config, SimpleScatterPlotParameters):
        logging.info("Creating Simple Scatter Plot")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
    elif isinstance(config, StackedBarChartPlotParameters):
        logging.info("Creating Bar Chart")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"Hue: {config.hue}")
        logging.info(f"Chart Orientation: {config.chart_orientation}")
        logging.info(f"Sort Order: {config.sort_order}")
    elif isinstance(config, SurfacePlotParameters):
        logging.info("Creating Surface Plot")
        logging.info(f"Function Name: {config.function_name}")
        logging.info(f"X-Axis Maximum: {config.x_axis_maximum}")
        logging.info(f"Y-Axis Maximum: {config.y_axis_maximum}")
        logging.info(f"X-Axis Label: {config.x_axis_label}")
        logging.info(f"Y-Axis Label: {config.y_axis_label}")
        logging.info(f"Z-Axis Label: {config.z_axis_label}")
        logging.info(f"Elevation Angle: {config.elevation_angle}")
        logging.info(f"Azimuth Angle: {config.azimuth_angle}")
    elif isinstance(config, ViolinPlotParameters):
        logging.info("Creating Violin Plot")
        logging.info(f"Variable X: {config.variable_x_axis}")
        logging.info(f"Variable Y: {config.variable_y_axis}")
        logging.info(f"X-Axis Label: {config.x_axis_label}")
        logging.info(f"Y-Axis Label: {config.y_axis_label}")
    else:
        raise ValueError(f"Invalid type of visualization requested {type(config)}")
    logging.info("```")
