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

import typing
import pathlib
from styxdefs import *

DCMINFO_METADATA = Metadata(
    id="f02767c67a910f0ef82176cc014707d1d17070a2.boutiques",
    name="dcminfo",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_DcminfoTagParamsDictNoTag = typing.TypedDict('_DcminfoTagParamsDictNoTag', {
    "group": str,
    "element": str,
})
DcminfoTagParamsDictTagged = typing.TypedDict('DcminfoTagParamsDictTagged', {
    "@type": typing.Literal["tag"],
    "group": str,
    "element": str,
})
DcminfoTagParamsDict = _DcminfoTagParamsDictNoTag | DcminfoTagParamsDictTagged


_DcminfoConfigParamsDictNoTag = typing.TypedDict('_DcminfoConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
DcminfoConfigParamsDictTagged = typing.TypedDict('DcminfoConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
DcminfoConfigParamsDict = _DcminfoConfigParamsDictNoTag | DcminfoConfigParamsDictTagged


_DcminfoParamsDictNoTag = typing.TypedDict('_DcminfoParamsDictNoTag', {
    "all": bool,
    "csa": bool,
    "phoenix": bool,
    "tag": typing.NotRequired[list[DcminfoTagParamsDict] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[DcminfoConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "file": InputPathType,
})
DcminfoParamsDictTagged = typing.TypedDict('DcminfoParamsDictTagged', {
    "@type": typing.Literal["mrtrix/dcminfo"],
    "all": bool,
    "csa": bool,
    "phoenix": bool,
    "tag": typing.NotRequired[list[DcminfoTagParamsDict] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[DcminfoConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "file": InputPathType,
})
DcminfoParamsDict = _DcminfoParamsDictNoTag | DcminfoParamsDictTagged


def dcminfo_tag(
    group: str,
    element: str,
) -> DcminfoTagParamsDictTagged:
    """
    Build parameters.
    
    Args:
        group: print field specified by the group & element tags supplied. Tags\
            should be supplied as Hexadecimal (i.e. as they appear in the -all\
            listing).
        element: print field specified by the group & element tags supplied.\
            Tags should be supplied as Hexadecimal (i.e. as they appear in the -all\
            listing).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "tag",
        "group": group,
        "element": element,
    }
    return params


def dcminfo_tag_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DcminfoTagParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("group", None) is None:
        raise StyxValidationError("`group` must not be None")
    if not isinstance(params["group"], str):
        raise StyxValidationError(f'`group` has the wrong type: Received `{type(params.get("group", None))}` expected `str`')
    if params.get("element", None) is None:
        raise StyxValidationError("`element` must not be None")
    if not isinstance(params["element"], str):
        raise StyxValidationError(f'`element` has the wrong type: Received `{type(params.get("element", None))}` expected `str`')


def dcminfo_tag_cargs(
    params: DcminfoTagParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-tag")
    cargs.append(params.get("group", None))
    cargs.append(params.get("element", None))
    return cargs


def dcminfo_config(
    key: str,
    value: str,
) -> DcminfoConfigParamsDictTagged:
    """
    Build parameters.
    
    Args:
        key: temporarily set the value of an MRtrix config file entry.
        value: temporarily set the value of an MRtrix config file entry.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "config",
        "key": key,
        "value": value,
    }
    return params


def dcminfo_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DcminfoConfigParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("key", None) is None:
        raise StyxValidationError("`key` must not be None")
    if not isinstance(params["key"], str):
        raise StyxValidationError(f'`key` has the wrong type: Received `{type(params.get("key", None))}` expected `str`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], str):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `str`')


def dcminfo_config_cargs(
    params: DcminfoConfigParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-config")
    cargs.append(params.get("key", None))
    cargs.append(params.get("value", None))
    return cargs


class DcminfoOutputs(typing.NamedTuple):
    """
    Output object returned when calling `DcminfoParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def dcminfo_params(
    file: InputPathType,
    all_: bool = False,
    csa: bool = False,
    phoenix: bool = False,
    tag: list[DcminfoTagParamsDict] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[DcminfoConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> DcminfoParamsDictTagged:
    """
    Build parameters.
    
    Args:
        file: the DICOM file to be scanned.
        all_: print all DICOM fields.
        csa: print all Siemens CSA fields (excluding Phoenix unless requested).
        phoenix: print Siemens Phoenix protocol information.
        tag: print field specified by the group & element tags supplied. Tags\
            should be supplied as Hexadecimal (i.e. as they appear in the -all\
            listing).
        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.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/dcminfo",
        "all": all_,
        "csa": csa,
        "phoenix": phoenix,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "file": file,
    }
    if tag is not None:
        params["tag"] = tag
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def dcminfo_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DcminfoParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("all", False) is None:
        raise StyxValidationError("`all` must not be None")
    if not isinstance(params["all"], bool):
        raise StyxValidationError(f'`all` has the wrong type: Received `{type(params.get("all", False))}` expected `bool`')
    if params.get("csa", False) is None:
        raise StyxValidationError("`csa` must not be None")
    if not isinstance(params["csa"], bool):
        raise StyxValidationError(f'`csa` has the wrong type: Received `{type(params.get("csa", False))}` expected `bool`')
    if params.get("phoenix", False) is None:
        raise StyxValidationError("`phoenix` must not be None")
    if not isinstance(params["phoenix"], bool):
        raise StyxValidationError(f'`phoenix` has the wrong type: Received `{type(params.get("phoenix", False))}` expected `bool`')
    if params.get("tag", None) is not None:
        if not isinstance(params["tag"], list):
            raise StyxValidationError(f'`tag` has the wrong type: Received `{type(params.get("tag", None))}` expected `list[DcminfoTagParamsDict] | None`')
        for e in params["tag"]:
            dcminfo_tag_validate(e)
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[DcminfoConfigParamsDict] | None`')
        for e in params["config"]:
            dcminfo_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
    if params.get("file", None) is None:
        raise StyxValidationError("`file` must not be None")
    if not isinstance(params["file"], (pathlib.Path, str)):
        raise StyxValidationError(f'`file` has the wrong type: Received `{type(params.get("file", None))}` expected `InputPathType`')


def dcminfo_cargs(
    params: DcminfoParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("dcminfo")
    if params.get("all", False):
        cargs.append("-all")
    if params.get("csa", False):
        cargs.append("-csa")
    if params.get("phoenix", False):
        cargs.append("-phoenix")
    if params.get("tag", None) is not None:
        cargs.extend([a for c in [dcminfo_tag_cargs(s, execution) for s in params.get("tag", None)] for a in c])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [dcminfo_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    cargs.append(execution.input_file(params.get("file", None)))
    return cargs


def dcminfo_outputs(
    params: DcminfoParamsDict,
    execution: Execution,
) -> DcminfoOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = DcminfoOutputs(
        root=execution.output_file("."),
    )
    return ret


def dcminfo_execute(
    params: DcminfoParamsDict,
    runner: Runner | None = None,
) -> DcminfoOutputs:
    """
    dcminfo
    
    Output DICOM fields in human-readable format.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DcminfoOutputs`).
    """
    dcminfo_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(DCMINFO_METADATA)
    params = execution.params(params)
    cargs = dcminfo_cargs(params, execution)
    ret = dcminfo_outputs(params, execution)
    execution.run(cargs)
    return ret


def dcminfo(
    file: InputPathType,
    all_: bool = False,
    csa: bool = False,
    phoenix: bool = False,
    tag: list[DcminfoTagParamsDict] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[DcminfoConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> DcminfoOutputs:
    """
    dcminfo
    
    Output DICOM fields in human-readable format.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        file: the DICOM file to be scanned.
        all_: print all DICOM fields.
        csa: print all Siemens CSA fields (excluding Phoenix unless requested).
        phoenix: print Siemens Phoenix protocol information.
        tag: print field specified by the group & element tags supplied. Tags\
            should be supplied as Hexadecimal (i.e. as they appear in the -all\
            listing).
        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 `DcminfoOutputs`).
    """
    params = dcminfo_params(
        all_=all_,
        csa=csa,
        phoenix=phoenix,
        tag=tag,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        file=file,
    )
    return dcminfo_execute(params, runner)


__all__ = [
    "DCMINFO_METADATA",
    "DcminfoConfigParamsDict",
    "DcminfoConfigParamsDictTagged",
    "DcminfoOutputs",
    "DcminfoParamsDict",
    "DcminfoParamsDictTagged",
    "DcminfoTagParamsDict",
    "DcminfoTagParamsDictTagged",
    "dcminfo",
    "dcminfo_config",
    "dcminfo_execute",
    "dcminfo_params",
    "dcminfo_tag",
]
