from pp_slurm import slurm_functions
from pathlib import Path

from breg_util.brainreg_command_line_util import brainreg_command


def brainreg_slurm(mtd, additional=None):
    # This is a hack right now and passes the actually used command via the additional_string
    # command, the rest is more or less irrelevant.
    brainreg_commands = brainreg_command(
                                          mtd.mouse_dir_derivatives,
                                          mtd.serial2p_dir,
                                          function="brainreg",
                                          atlas="kim_mouse_10um",
                                          additional=additional
    )

    print(f"The following commands will be executed: {brainreg_commands}")

    for cmd in brainreg_commands:
        kwarg_dict = {
            "slurm_batch": True,
            "logs_path": Path(f"{mtd.mouse_dir_derivatives}") / "logs",
            "mouse_dir": f"{mtd.mouse_dir_derivatives}",
            "function": "brainreg",
            "atlas": "kim_mouse_10um",
            "module_string": "brainglobe",
            "additional_string": cmd,
        }
        slurm_functions.run_brainreg_slurm(**kwarg_dict)
