from .classification import ClassificationEvaluator
from .regression import RegressionEvaluator
from .result import EvaluationResult
from .core.inspector import get_model_type


def evaluate(model, X_test, y_test, parallel: bool = False) -> dict:
    """
    Public evaluation entry point.

    Automatically selects the correct evaluator
    based on model type.

    Parameters
    ----------
    model : object
        Trained model implementing `predict`.
    X_test : array-like
        Test features.
    y_test : array-like
        True labels.
    parallel : bool, default=False
        Whether to enable parallel computation.

    Returns
    -------
    dict
        Dictionary containing computed metrics.

    Raises
    ------
    ValueError
        If model type is unsupported.
    """

    model_type = get_model_type(model)

    if model_type == "classification":
        evaluator = ClassificationEvaluator(model, X_test, y_test, parallel)

    elif model_type == "regression":
        evaluator = RegressionEvaluator(model, X_test, y_test, parallel)

    else:
        raise ValueError("Unsupported model type")

    return EvaluationResult(evaluator.evaluate(), model_type)