import logging


def persist_experts_in_physical_partition(
    folder_path="results",
    results=None,
    persist_cv_results=False,
    persist_cv_data=False,
    persist_model_reprs=False,
    persist_best_model=False,
    persist_partition=False,
    persist_model_selector_results=True,
):
    """Store expert files for each partition.

    The file names follow {partition_hash}.{expert_type} e.g. 795dab1813f05b1abe9ae6ded93e1ec4.cv_data

    Parameters
    ----------
    results : list of ModelSelectorResults
        results of model selection for each partition

    folder_path : str
        Path to the directory, where expert files are stored,
        by default '' resulting in current working directory

    persist_cv_results : bool
        If True `cv_results` of sklearn.model_selection.GridSearchCV as pandas df will be saved as pickle
        for each partition

    persist_cv_data : bool
        If True the pandas df detail cv data will be saved as pickle for each partition

    persist_model_reprs : bool
        If True model reprs will be saved as json for each partition

    persist_best_model : bool
        If True best model will be saved as pickle for each partition

    persist_partition : bool
        If True dictionary of partition label will be saved
        as json for each partition

    persist_model_selector_results : bool
        If True ModelSelectoResults with all important information will be saved
        as pickle for each partition

    Returns
    -------
    str
        Folder path where experts were stored
    """
    if results is not None:
        for result in results:
            if persist_best_model:
                result.persist(attribute_name="best_model", path=folder_path)
            if persist_partition:
                result.persist(attribute_name="partition", path=folder_path)
            if persist_model_selector_results:
                result.persist(path=folder_path)
            if persist_cv_results:
                result.persist(attribute_name="cv_results", path=folder_path)
            if persist_cv_data:
                result.persist(attribute_name="cv_data", path=folder_path)
            if persist_model_reprs:
                result.persist(attribute_name="model_reprs", path=folder_path)
    else:
        logging.info("You passed empty results. Nothing is being persisted.")

    return folder_path