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

import typing
import pathlib
from styxdefs import *

CIFTI_PARCEL_MAPPING_TO_LABEL_METADATA = Metadata(
    id="ce08a74db6f042fde95fefc290e8baf47feda5cc.workbench",
    name="cifti-parcel-mapping-to-label",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiParcelMappingToLabelParamsDictNoTag = typing.TypedDict('_CiftiParcelMappingToLabelParamsDictNoTag', {
    "cifti-in": InputPathType,
    "direction": str,
    "template-cifti": InputPathType,
    "dlabel-out": str,
})
CiftiParcelMappingToLabelParamsDictTagged = typing.TypedDict('CiftiParcelMappingToLabelParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-parcel-mapping-to-label"],
    "cifti-in": InputPathType,
    "direction": str,
    "template-cifti": InputPathType,
    "dlabel-out": str,
})
CiftiParcelMappingToLabelParamsDict = _CiftiParcelMappingToLabelParamsDictNoTag | CiftiParcelMappingToLabelParamsDictTagged


class CiftiParcelMappingToLabelOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiParcelMappingToLabelParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    dlabel_out: OutputPathType
    """the output dense label file"""


def cifti_parcel_mapping_to_label_params(
    cifti_in: InputPathType,
    direction: str,
    template_cifti: InputPathType,
    dlabel_out: str,
) -> CiftiParcelMappingToLabelParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the input parcellated file.
        direction: which dimension to take the parcel map from, ROW or COLUMN.
        template_cifti: a cifti file with the desired dense mapping along\
            column.
        dlabel_out: the output dense label file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-parcel-mapping-to-label",
        "cifti-in": cifti_in,
        "direction": direction,
        "template-cifti": template_cifti,
        "dlabel-out": dlabel_out,
    }
    return params


def cifti_parcel_mapping_to_label_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiParcelMappingToLabelParamsDict` 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("cifti-in", None) is None:
        raise StyxValidationError("`cifti-in` must not be None")
    if not isinstance(params["cifti-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-in` has the wrong type: Received `{type(params.get("cifti-in", None))}` expected `InputPathType`')
    if params.get("direction", None) is None:
        raise StyxValidationError("`direction` must not be None")
    if not isinstance(params["direction"], str):
        raise StyxValidationError(f'`direction` has the wrong type: Received `{type(params.get("direction", None))}` expected `str`')
    if params.get("template-cifti", None) is None:
        raise StyxValidationError("`template-cifti` must not be None")
    if not isinstance(params["template-cifti"], (pathlib.Path, str)):
        raise StyxValidationError(f'`template-cifti` has the wrong type: Received `{type(params.get("template-cifti", None))}` expected `InputPathType`')
    if params.get("dlabel-out", None) is None:
        raise StyxValidationError("`dlabel-out` must not be None")
    if not isinstance(params["dlabel-out"], str):
        raise StyxValidationError(f'`dlabel-out` has the wrong type: Received `{type(params.get("dlabel-out", None))}` expected `str`')


def cifti_parcel_mapping_to_label_cargs(
    params: CiftiParcelMappingToLabelParamsDict,
    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",
        "-cifti-parcel-mapping-to-label"
    ])
    cargs.append(execution.input_file(params.get("cifti-in", None)))
    cargs.append(params.get("direction", None))
    cargs.append(execution.input_file(params.get("template-cifti", None)))
    cargs.append(params.get("dlabel-out", None))
    return cargs


def cifti_parcel_mapping_to_label_outputs(
    params: CiftiParcelMappingToLabelParamsDict,
    execution: Execution,
) -> CiftiParcelMappingToLabelOutputs:
    """
    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 = CiftiParcelMappingToLabelOutputs(
        root=execution.output_file("."),
        dlabel_out=execution.output_file(params.get("dlabel-out", None)),
    )
    return ret


def cifti_parcel_mapping_to_label_execute(
    params: CiftiParcelMappingToLabelParamsDict,
    runner: Runner | None = None,
) -> CiftiParcelMappingToLabelOutputs:
    """
    CREATE DLABEL FROM PARCELLATED FILE.
    
    This command will output a dlabel file, useful for doing the same
    parcellation to another dense file.
    
    For ptseries, pscalar, plabel, pconn, and pdconn, using COLUMN for
    <direction> will work.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiParcelMappingToLabelOutputs`).
    """
    cifti_parcel_mapping_to_label_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_PARCEL_MAPPING_TO_LABEL_METADATA)
    params = execution.params(params)
    cargs = cifti_parcel_mapping_to_label_cargs(params, execution)
    ret = cifti_parcel_mapping_to_label_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_parcel_mapping_to_label(
    cifti_in: InputPathType,
    direction: str,
    template_cifti: InputPathType,
    dlabel_out: str,
    runner: Runner | None = None,
) -> CiftiParcelMappingToLabelOutputs:
    """
    CREATE DLABEL FROM PARCELLATED FILE.
    
    This command will output a dlabel file, useful for doing the same
    parcellation to another dense file.
    
    For ptseries, pscalar, plabel, pconn, and pdconn, using COLUMN for
    <direction> will work.
    
    Args:
        cifti_in: the input parcellated file.
        direction: which dimension to take the parcel map from, ROW or COLUMN.
        template_cifti: a cifti file with the desired dense mapping along\
            column.
        dlabel_out: the output dense label file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiParcelMappingToLabelOutputs`).
    """
    params = cifti_parcel_mapping_to_label_params(
        cifti_in=cifti_in,
        direction=direction,
        template_cifti=template_cifti,
        dlabel_out=dlabel_out,
    )
    return cifti_parcel_mapping_to_label_execute(params, runner)


__all__ = [
    "CIFTI_PARCEL_MAPPING_TO_LABEL_METADATA",
    "CiftiParcelMappingToLabelOutputs",
    "CiftiParcelMappingToLabelParamsDict",
    "CiftiParcelMappingToLabelParamsDictTagged",
    "cifti_parcel_mapping_to_label",
    "cifti_parcel_mapping_to_label_execute",
    "cifti_parcel_mapping_to_label_params",
]
