from __future__ import annotations

from typing import Any

try:
    from sklearn import metrics, model_selection, preprocessing
except ModuleNotFoundError:
    pass  # error message in typing.py

from .utils import sarus_external_op


@sarus_external_op
async def model_fit(model: Any, *args: Any, **kwargs: Any) -> Any:
    fitted_model = model.fit(*args, **kwargs)
    return fitted_model


@sarus_external_op
async def sk_scale(val: Any, *args: Any, **kwargs: Any) -> Any:
    return preprocessing.scale(val, *args, **kwargs)


@sarus_external_op
async def sk_cross_val_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return model_selection.cross_val_score(*args, **kwargs)


@sarus_external_op
async def sk_train_test_split(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return model_selection.train_test_split(*args, **kwargs)


# metrics
@sarus_external_op
async def sk_accuracy_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.accuracy_score(*args, **kwargs)


@sarus_external_op
async def sk_average_precision_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.average_precision_score(*args, **kwargs)


@sarus_external_op
async def sk_classification_report(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.classification_report(*args, **kwargs)


@sarus_external_op
async def sk_confusion_matrix(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.confusion_matrix(*args, **kwargs)


@sarus_external_op
async def sk_f1_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.f1_score(*args, **kwargs)


@sarus_external_op
async def sk_plot_confusion_matrix(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.plot_confusion_matrix(*args, **kwargs)


@sarus_external_op
async def sk_precision_recall_curve(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.precision_recall_curve(*args, **kwargs)


@sarus_external_op
async def sk_precision_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.precision_score(*args, **kwargs)


@sarus_external_op
async def sk_recall_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.recall_score(*args, **kwargs)


@sarus_external_op
async def sk_roc_auc_score(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.roc_auc_score(*args, **kwargs)


@sarus_external_op
async def sk_roc_curve(
    *args: Any,
    **kwargs: Any,
) -> Any:
    return metrics.roc_curve(*args, **kwargs)


@sarus_external_op
async def sk_random_forest_classifier_predict(
    model: Any,
    *args: Any,
    **kwargs: Any,
) -> Any:
    y_pred = model.predict(*args, **kwargs)
    return y_pred


@sarus_external_op
async def sk_label_encoder_fit_transform(
    model: Any,
    *args: Any,
    **kwargs: Any,
) -> Any:
    X_transformed = model.fit_transform(*args, **kwargs)
    return X_transformed
