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

import typing
import pathlib
from styxdefs import *

VOLUME_COMPONENTS_TO_FRAMES_METADATA = Metadata(
    id="62835d3af56370841cd14095a4b69710f24db721.workbench",
    name="volume-components-to-frames",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_VolumeComponentsToFramesParamsDictNoTag = typing.TypedDict('_VolumeComponentsToFramesParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
})
VolumeComponentsToFramesParamsDictTagged = typing.TypedDict('VolumeComponentsToFramesParamsDictTagged', {
    "@type": typing.Literal["workbench/volume-components-to-frames"],
    "input": InputPathType,
    "output": str,
})
VolumeComponentsToFramesParamsDict = _VolumeComponentsToFramesParamsDictNoTag | VolumeComponentsToFramesParamsDictTagged


class VolumeComponentsToFramesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeComponentsToFramesParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the input volume converted to multiple frames of scalar type"""


def volume_components_to_frames_params(
    input_: InputPathType,
    output: str,
) -> VolumeComponentsToFramesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: the RGB/complex-type volume.
        output: the input volume converted to multiple frames of scalar type.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-components-to-frames",
        "input": input_,
        "output": output,
    }
    return params


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


def volume_components_to_frames_cargs(
    params: VolumeComponentsToFramesParamsDict,
    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",
        "-volume-components-to-frames"
    ])
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    return cargs


def volume_components_to_frames_outputs(
    params: VolumeComponentsToFramesParamsDict,
    execution: Execution,
) -> VolumeComponentsToFramesOutputs:
    """
    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 = VolumeComponentsToFramesOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def volume_components_to_frames_execute(
    params: VolumeComponentsToFramesParamsDict,
    runner: Runner | None = None,
) -> VolumeComponentsToFramesOutputs:
    """
    CONVERT RGB/COMPLEX VOLUME TO FRAMES.
    
    RGB and complex datatypes are not always well supported, this command allows
    separating them into standard subvolumes for better support.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeComponentsToFramesOutputs`).
    """
    volume_components_to_frames_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_COMPONENTS_TO_FRAMES_METADATA)
    params = execution.params(params)
    cargs = volume_components_to_frames_cargs(params, execution)
    ret = volume_components_to_frames_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_components_to_frames(
    input_: InputPathType,
    output: str,
    runner: Runner | None = None,
) -> VolumeComponentsToFramesOutputs:
    """
    CONVERT RGB/COMPLEX VOLUME TO FRAMES.
    
    RGB and complex datatypes are not always well supported, this command allows
    separating them into standard subvolumes for better support.
    
    Args:
        input_: the RGB/complex-type volume.
        output: the input volume converted to multiple frames of scalar type.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeComponentsToFramesOutputs`).
    """
    params = volume_components_to_frames_params(
        input_=input_,
        output=output,
    )
    return volume_components_to_frames_execute(params, runner)


__all__ = [
    "VOLUME_COMPONENTS_TO_FRAMES_METADATA",
    "VolumeComponentsToFramesOutputs",
    "VolumeComponentsToFramesParamsDict",
    "VolumeComponentsToFramesParamsDictTagged",
    "volume_components_to_frames",
    "volume_components_to_frames_execute",
    "volume_components_to_frames_params",
]
