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

import typing
import pathlib
from styxdefs import *

NIFTI_INFORMATION_METADATA = Metadata(
    id="e9c11d632fc070fafb7efd4e280c2753fca13b1e.workbench",
    name="nifti-information",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_NiftiInformationPrintXmlParamsDictNoTag = typing.TypedDict('_NiftiInformationPrintXmlParamsDictNoTag', {
    "version": typing.NotRequired[str | None],
})
NiftiInformationPrintXmlParamsDictTagged = typing.TypedDict('NiftiInformationPrintXmlParamsDictTagged', {
    "@type": typing.Literal["print-xml"],
    "version": typing.NotRequired[str | None],
})
NiftiInformationPrintXmlParamsDict = _NiftiInformationPrintXmlParamsDictNoTag | NiftiInformationPrintXmlParamsDictTagged


_NiftiInformationParamsDictNoTag = typing.TypedDict('_NiftiInformationParamsDictNoTag', {
    "nifti-file": str,
    "print-xml": typing.NotRequired[NiftiInformationPrintXmlParamsDict | None],
    "allow-truncated": typing.NotRequired[bool | None],
    "print-matrix": bool,
})
NiftiInformationParamsDictTagged = typing.TypedDict('NiftiInformationParamsDictTagged', {
    "@type": typing.Literal["workbench/nifti-information"],
    "nifti-file": str,
    "print-xml": typing.NotRequired[NiftiInformationPrintXmlParamsDict | None],
    "allow-truncated": typing.NotRequired[bool | None],
    "print-matrix": bool,
})
NiftiInformationParamsDict = _NiftiInformationParamsDictNoTag | NiftiInformationParamsDictTagged


def nifti_information_print_xml(
    version: str | None = None,
) -> NiftiInformationPrintXmlParamsDictTagged:
    """
    Build parameters.
    
    Args:
        version: convert the XML to a specific CIFTI version (default is the\
            file's cifti version)\
            \
            the CIFTI version to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "print-xml",
    }
    if version is not None:
        params["version"] = version
    return params


def nifti_information_print_xml_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `NiftiInformationPrintXmlParamsDict` 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("version", None) is not None:
        if not isinstance(params["version"], str):
            raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", None))}` expected `str | None`')


def nifti_information_print_xml_cargs(
    params: NiftiInformationPrintXmlParamsDict,
    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("-print-xml")
    if params.get("version", None) is not None:
        cargs.extend([
            "-version",
            params.get("version", None)
        ])
    return cargs


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


def nifti_information_params(
    nifti_file: str,
    print_xml: NiftiInformationPrintXmlParamsDict | None = None,
    allow_truncated: bool | None = None,
    print_matrix: bool = False,
) -> NiftiInformationParamsDictTagged:
    """
    Build parameters.
    
    Args:
        nifti_file: the nifti/cifti file to examine.
        print_xml: print the cifti XML (cifti only).
        allow_truncated: display the header contents\
            \
            print the header even if the data is truncated.
        print_matrix: output the values in the matrix (cifti only).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/nifti-information",
        "nifti-file": nifti_file,
        "print-matrix": print_matrix,
    }
    if print_xml is not None:
        params["print-xml"] = print_xml
    if allow_truncated is not None:
        params["allow-truncated"] = allow_truncated
    return params


def nifti_information_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `NiftiInformationParamsDict` 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("nifti-file", None) is None:
        raise StyxValidationError("`nifti-file` must not be None")
    if not isinstance(params["nifti-file"], str):
        raise StyxValidationError(f'`nifti-file` has the wrong type: Received `{type(params.get("nifti-file", None))}` expected `str`')
    if params.get("print-xml", None) is not None:
        nifti_information_print_xml_validate(params["print-xml"])
    if params.get("allow-truncated", None) is not None:
        if not isinstance(params["allow-truncated"], bool):
            raise StyxValidationError(f'`allow-truncated` has the wrong type: Received `{type(params.get("allow-truncated", None))}` expected `bool | None`')
    if params.get("print-matrix", False) is None:
        raise StyxValidationError("`print-matrix` must not be None")
    if not isinstance(params["print-matrix"], bool):
        raise StyxValidationError(f'`print-matrix` has the wrong type: Received `{type(params.get("print-matrix", False))}` expected `bool`')


def nifti_information_cargs(
    params: NiftiInformationParamsDict,
    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.extend([
        "wb_command",
        "-nifti-information"
    ])
    cargs.append(params.get("nifti-file", None))
    if params.get("print-xml", None) is not None:
        cargs.extend(nifti_information_print_xml_cargs(params.get("print-xml", None), execution))
    if params.get("allow-truncated", None) is not None:
        cargs.extend([
            "-print-header",
            "-allow-truncated"
        ])
    if params.get("print-matrix", False):
        cargs.append("-print-matrix")
    return cargs


def nifti_information_outputs(
    params: NiftiInformationParamsDict,
    execution: Execution,
) -> NiftiInformationOutputs:
    """
    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 = NiftiInformationOutputs(
        root=execution.output_file("."),
    )
    return ret


def nifti_information_execute(
    params: NiftiInformationParamsDict,
    runner: Runner | None = None,
) -> NiftiInformationOutputs:
    """
    DISPLAY INFORMATION ABOUT A NIFTI/CIFTI FILE.
    
    You must specify at least one -print-* option.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `NiftiInformationOutputs`).
    """
    nifti_information_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(NIFTI_INFORMATION_METADATA)
    params = execution.params(params)
    cargs = nifti_information_cargs(params, execution)
    ret = nifti_information_outputs(params, execution)
    execution.run(cargs)
    return ret


def nifti_information(
    nifti_file: str,
    print_xml: NiftiInformationPrintXmlParamsDict | None = None,
    allow_truncated: bool | None = None,
    print_matrix: bool = False,
    runner: Runner | None = None,
) -> NiftiInformationOutputs:
    """
    DISPLAY INFORMATION ABOUT A NIFTI/CIFTI FILE.
    
    You must specify at least one -print-* option.
    
    Args:
        nifti_file: the nifti/cifti file to examine.
        print_xml: print the cifti XML (cifti only).
        allow_truncated: display the header contents\
            \
            print the header even if the data is truncated.
        print_matrix: output the values in the matrix (cifti only).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `NiftiInformationOutputs`).
    """
    params = nifti_information_params(
        nifti_file=nifti_file,
        print_xml=print_xml,
        allow_truncated=allow_truncated,
        print_matrix=print_matrix,
    )
    return nifti_information_execute(params, runner)


__all__ = [
    "NIFTI_INFORMATION_METADATA",
    "NiftiInformationOutputs",
    "NiftiInformationParamsDict",
    "NiftiInformationParamsDictTagged",
    "NiftiInformationPrintXmlParamsDict",
    "NiftiInformationPrintXmlParamsDictTagged",
    "nifti_information",
    "nifti_information_execute",
    "nifti_information_params",
    "nifti_information_print_xml",
]
