import os
import yaml

# This module is used to read and write training settings from yaml files
# The settings are used to train the neural network and also for methyltion analysis
# for example user can use different training settings and different states of the neural network both for training and evaluation(methylaion analysis)


def save_training_settings(settings_dict, yaml_settings_path):

    with open(yaml_settings_path, "w") as file:
        yamlfile = yaml.dump(settings_dict, file, sort_keys=False)


def read_settings(yaml_settings_path):

    with open(yaml_settings_path) as file:

        yamldict = yaml.load(file, Loader=yaml.FullLoader)
    return yamldict


def settings_check_exists(project_path):
    print("checking if training settings exist")
    return True


def get_training_settings_template(settings_save_path):
    print(f"Copying default setting to - {settings_save_path}")
    training_dict = read_settings(
        os.path.join(os.path.dirname(__file__), "training_settings.yaml")
    )
    save_training_settings(training_dict, settings_save_path)
    input("Press enter to quit and edit the settings file")
    quit()


def settings_import(project_path, settings_import_file=None):
    if settings_import_file == None:
        print("Loading default training settings file")
        training_dict = read_settings(
            os.path.join(os.path.dirname(__file__), "training_settings.yaml")
        )
    else:
        if os.path.isfile(settings_import_file):
            print(f"Loading custom training settings file - {settings_import_file}")
            training_dict = read_settings(settings_import_file)
        else:
            print(f"Custom training settings file not found")
            get_training_settings_template(settings_import_file)

    return training_dict


if __name__ == "__main__":
    print("project settings - direct")


else:
    pass
