# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *
import dataclasses

DIRMERGE_METADATA = Metadata(
    id="3ce611683ba7275413635b52cfd65e02dc5a3ec7.boutiques",
    name="dirmerge",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


@dataclasses.dataclass
class DirmergeConfig:
    """
    temporarily set the value of an MRtrix config file entry.
    """
    key: str
    """temporarily set the value of an MRtrix config file entry."""
    value: str
    """temporarily set the value of an MRtrix config file entry."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-config")
        cargs.append(self.key)
        cargs.append(self.value)
        return cargs


class DirmergeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `dirmerge(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out: OutputPathType
    """the output directions file, with each row listing the X Y Z gradient
    directions, the b-value, and an index representing the phase encode
    direction"""


def dirmerge(
    subsets: int,
    bvalue_files: list[str],
    out: str,
    unipolar_weight: float | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[DirmergeConfig] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> DirmergeOutputs:
    """
    Splice / merge multiple sets of directions in such a way as to maintain
    near-optimality upon truncation.
    
    
    
    References:
    
    .
    
    Author: J-Donald Tournier (jdtournier@gmail.com)
    
    URL:
    https://mrtrix.readthedocs.io/en/latest/reference/commands/dirmerge.html
    
    Args:
        subsets: the number of subsets (eg. phase encoding directions) per\
            b-value.
        bvalue_files: the b-value and sets of corresponding files, in order.
        out: the output directions file, with each row listing the X Y Z\
            gradient directions, the b-value, and an index representing the phase\
            encode direction.
        unipolar_weight: set the weight given to the unipolar electrostatic\
            repulsion model compared to the bipolar model (default: 0.2).
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DirmergeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(DIRMERGE_METADATA)
    cargs = []
    cargs.append("dirmerge")
    if unipolar_weight is not None:
        cargs.extend([
            "-unipolar_weight",
            str(unipolar_weight)
        ])
    if info:
        cargs.append("-info")
    if quiet:
        cargs.append("-quiet")
    if debug:
        cargs.append("-debug")
    if force:
        cargs.append("-force")
    if nthreads is not None:
        cargs.extend([
            "-nthreads",
            str(nthreads)
        ])
    if config is not None:
        cargs.extend([a for c in [s.run(execution) for s in config] for a in c])
    if help_:
        cargs.append("-help")
    if version:
        cargs.append("-version")
    cargs.append(str(subsets))
    cargs.extend(bvalue_files)
    cargs.append(out)
    ret = DirmergeOutputs(
        root=execution.output_file("."),
        out=execution.output_file(out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DIRMERGE_METADATA",
    "DirmergeConfig",
    "DirmergeOutputs",
    "dirmerge",
]
