from typing import Any, Dict, List, Tuple
import time

from ddi_fw.ml.evaluation_helper import Metrics

class Result:
    def __init__(self) -> None:
        self.log_dict = {}
        self.metric_dict = {}

    def add_log(self, key, logs):
        self.log_dict[key] = logs

    def add_metric(self, key, metrics):
        self.metric_dict[key] = metrics


class ModelWrapper:
    def __init__(self, date, descriptor, model_func ,**kwargs):
        self.date = date
        self.descriptor = descriptor
        self.model_func = model_func
        self.kwargs = kwargs
        self.elapsed_time: float | None = None
       

    def set_data(self, train_idx_arr, val_idx_arr, train_data, train_label, test_data, test_label):
        self.train_idx_arr = train_idx_arr
        self.val_idx_arr = val_idx_arr
        self.train_data = train_data
        self.train_label = train_label
        self.test_data = test_data
        self.test_label = test_label

    def _predict(self, model, X)-> Any:
        pass
    
    def predict(self)-> Any:
        pass

    def fit_model(self, X_train, y_train, X_valid, y_valid)-> Any:
        pass
    
    def fit(self)-> Any:
        pass
    
        # 🧠 Automatically wraps fit_model() when subclassing
    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)

        if hasattr(cls, "fit"):
            original_method = cls.fit

            def timed_fit(self, *args, **kwargs):
                start = time.perf_counter()
                result = original_method(self, *args, **kwargs)
                self.elapsed_time = time.perf_counter() - start
                return result

            cls.fit = timed_fit