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

import typing
import pathlib
from styxdefs import *

VOLUME_CREATE_METADATA = Metadata(
    id="0ea13854b7a75326c4a105c15f5a5b8318a5d533.workbench",
    name="volume-create",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_VolumeCreatePlumbParamsDictNoTag = typing.TypedDict('_VolumeCreatePlumbParamsDictNoTag', {
    "axis-order": str,
    "x-spacing": float,
    "y-spacing": float,
    "z-spacing": float,
    "x-offset": float,
    "y-offset": float,
    "z-offset": float,
})
VolumeCreatePlumbParamsDictTagged = typing.TypedDict('VolumeCreatePlumbParamsDictTagged', {
    "@type": typing.Literal["plumb"],
    "axis-order": str,
    "x-spacing": float,
    "y-spacing": float,
    "z-spacing": float,
    "x-offset": float,
    "y-offset": float,
    "z-offset": float,
})
VolumeCreatePlumbParamsDict = _VolumeCreatePlumbParamsDictNoTag | VolumeCreatePlumbParamsDictTagged


_VolumeCreateSformParamsDictNoTag = typing.TypedDict('_VolumeCreateSformParamsDictNoTag', {
    "xi-spacing": float,
    "xj-spacing": float,
    "xk-spacing": float,
    "x-offset": float,
    "yi-spacing": float,
    "yj-spacing": float,
    "yk-spacing": float,
    "y-offset": float,
    "zi-spacing": float,
    "zj-spacing": float,
    "zk-spacing": float,
    "z-offset": float,
})
VolumeCreateSformParamsDictTagged = typing.TypedDict('VolumeCreateSformParamsDictTagged', {
    "@type": typing.Literal["sform"],
    "xi-spacing": float,
    "xj-spacing": float,
    "xk-spacing": float,
    "x-offset": float,
    "yi-spacing": float,
    "yj-spacing": float,
    "yk-spacing": float,
    "y-offset": float,
    "zi-spacing": float,
    "zj-spacing": float,
    "zk-spacing": float,
    "z-offset": float,
})
VolumeCreateSformParamsDict = _VolumeCreateSformParamsDictNoTag | VolumeCreateSformParamsDictTagged


_VolumeCreateParamsDictNoTag = typing.TypedDict('_VolumeCreateParamsDictNoTag', {
    "i-dim": int,
    "j-dim": int,
    "k-dim": int,
    "volume-out": str,
    "plumb": typing.NotRequired[VolumeCreatePlumbParamsDict | None],
    "sform": typing.NotRequired[VolumeCreateSformParamsDict | None],
})
VolumeCreateParamsDictTagged = typing.TypedDict('VolumeCreateParamsDictTagged', {
    "@type": typing.Literal["workbench/volume-create"],
    "i-dim": int,
    "j-dim": int,
    "k-dim": int,
    "volume-out": str,
    "plumb": typing.NotRequired[VolumeCreatePlumbParamsDict | None],
    "sform": typing.NotRequired[VolumeCreateSformParamsDict | None],
})
VolumeCreateParamsDict = _VolumeCreateParamsDictNoTag | VolumeCreateParamsDictTagged


def volume_create_plumb(
    axis_order: str,
    x_spacing: float,
    y_spacing: float,
    z_spacing: float,
    x_offset: float,
    y_offset: float,
    z_offset: float,
) -> VolumeCreatePlumbParamsDictTagged:
    """
    Build parameters.
    
    Args:
        axis_order: a string like 'XYZ' that specifies which index is along\
            which spatial dimension.
        x_spacing: change in x-coordinate from incrementing the relevant index.
        y_spacing: change in y-coordinate from incrementing the relevant index.
        z_spacing: change in z-coordinate from incrementing the relevant index.
        x_offset: the x-coordinate of the center of the first voxel.
        y_offset: the y-coordinate of the center of the first voxel.
        z_offset: the z-coordinate of the center of the first voxel.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "plumb",
        "axis-order": axis_order,
        "x-spacing": x_spacing,
        "y-spacing": y_spacing,
        "z-spacing": z_spacing,
        "x-offset": x_offset,
        "y-offset": y_offset,
        "z-offset": z_offset,
    }
    return params


def volume_create_plumb_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `VolumeCreatePlumbParamsDict` 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("axis-order", None) is None:
        raise StyxValidationError("`axis-order` must not be None")
    if not isinstance(params["axis-order"], str):
        raise StyxValidationError(f'`axis-order` has the wrong type: Received `{type(params.get("axis-order", None))}` expected `str`')
    if params.get("x-spacing", None) is None:
        raise StyxValidationError("`x-spacing` must not be None")
    if not isinstance(params["x-spacing"], (float, int)):
        raise StyxValidationError(f'`x-spacing` has the wrong type: Received `{type(params.get("x-spacing", None))}` expected `float`')
    if params.get("y-spacing", None) is None:
        raise StyxValidationError("`y-spacing` must not be None")
    if not isinstance(params["y-spacing"], (float, int)):
        raise StyxValidationError(f'`y-spacing` has the wrong type: Received `{type(params.get("y-spacing", None))}` expected `float`')
    if params.get("z-spacing", None) is None:
        raise StyxValidationError("`z-spacing` must not be None")
    if not isinstance(params["z-spacing"], (float, int)):
        raise StyxValidationError(f'`z-spacing` has the wrong type: Received `{type(params.get("z-spacing", None))}` expected `float`')
    if params.get("x-offset", None) is None:
        raise StyxValidationError("`x-offset` must not be None")
    if not isinstance(params["x-offset"], (float, int)):
        raise StyxValidationError(f'`x-offset` has the wrong type: Received `{type(params.get("x-offset", None))}` expected `float`')
    if params.get("y-offset", None) is None:
        raise StyxValidationError("`y-offset` must not be None")
    if not isinstance(params["y-offset"], (float, int)):
        raise StyxValidationError(f'`y-offset` has the wrong type: Received `{type(params.get("y-offset", None))}` expected `float`')
    if params.get("z-offset", None) is None:
        raise StyxValidationError("`z-offset` must not be None")
    if not isinstance(params["z-offset"], (float, int)):
        raise StyxValidationError(f'`z-offset` has the wrong type: Received `{type(params.get("z-offset", None))}` expected `float`')


def volume_create_plumb_cargs(
    params: VolumeCreatePlumbParamsDict,
    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([
        "-plumb",
        params.get("axis-order", None),
        str(params.get("x-spacing", None)),
        str(params.get("y-spacing", None)),
        str(params.get("z-spacing", None)),
        str(params.get("x-offset", None)),
        str(params.get("y-offset", None)),
        str(params.get("z-offset", None))
    ])
    return cargs


def volume_create_sform(
    xi_spacing: float,
    xj_spacing: float,
    xk_spacing: float,
    x_offset: float,
    yi_spacing: float,
    yj_spacing: float,
    yk_spacing: float,
    y_offset: float,
    zi_spacing: float,
    zj_spacing: float,
    zk_spacing: float,
    z_offset: float,
) -> VolumeCreateSformParamsDictTagged:
    """
    Build parameters.
    
    Args:
        xi_spacing: increase in x coordinate from incrementing the i index.
        xj_spacing: increase in x coordinate from incrementing the j index.
        xk_spacing: increase in x coordinate from incrementing the k index.
        x_offset: x coordinate of first voxel.
        yi_spacing: increase in y coordinate from incrementing the i index.
        yj_spacing: increase in y coordinate from incrementing the j index.
        yk_spacing: increase in y coordinate from incrementing the k index.
        y_offset: y coordinate of first voxel.
        zi_spacing: increase in z coordinate from incrementing the i index.
        zj_spacing: increase in z coordinate from incrementing the j index.
        zk_spacing: increase in z coordinate from incrementing the k index.
        z_offset: z coordinate of first voxel.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "sform",
        "xi-spacing": xi_spacing,
        "xj-spacing": xj_spacing,
        "xk-spacing": xk_spacing,
        "x-offset": x_offset,
        "yi-spacing": yi_spacing,
        "yj-spacing": yj_spacing,
        "yk-spacing": yk_spacing,
        "y-offset": y_offset,
        "zi-spacing": zi_spacing,
        "zj-spacing": zj_spacing,
        "zk-spacing": zk_spacing,
        "z-offset": z_offset,
    }
    return params


def volume_create_sform_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `VolumeCreateSformParamsDict` 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("xi-spacing", None) is None:
        raise StyxValidationError("`xi-spacing` must not be None")
    if not isinstance(params["xi-spacing"], (float, int)):
        raise StyxValidationError(f'`xi-spacing` has the wrong type: Received `{type(params.get("xi-spacing", None))}` expected `float`')
    if params.get("xj-spacing", None) is None:
        raise StyxValidationError("`xj-spacing` must not be None")
    if not isinstance(params["xj-spacing"], (float, int)):
        raise StyxValidationError(f'`xj-spacing` has the wrong type: Received `{type(params.get("xj-spacing", None))}` expected `float`')
    if params.get("xk-spacing", None) is None:
        raise StyxValidationError("`xk-spacing` must not be None")
    if not isinstance(params["xk-spacing"], (float, int)):
        raise StyxValidationError(f'`xk-spacing` has the wrong type: Received `{type(params.get("xk-spacing", None))}` expected `float`')
    if params.get("x-offset", None) is None:
        raise StyxValidationError("`x-offset` must not be None")
    if not isinstance(params["x-offset"], (float, int)):
        raise StyxValidationError(f'`x-offset` has the wrong type: Received `{type(params.get("x-offset", None))}` expected `float`')
    if params.get("yi-spacing", None) is None:
        raise StyxValidationError("`yi-spacing` must not be None")
    if not isinstance(params["yi-spacing"], (float, int)):
        raise StyxValidationError(f'`yi-spacing` has the wrong type: Received `{type(params.get("yi-spacing", None))}` expected `float`')
    if params.get("yj-spacing", None) is None:
        raise StyxValidationError("`yj-spacing` must not be None")
    if not isinstance(params["yj-spacing"], (float, int)):
        raise StyxValidationError(f'`yj-spacing` has the wrong type: Received `{type(params.get("yj-spacing", None))}` expected `float`')
    if params.get("yk-spacing", None) is None:
        raise StyxValidationError("`yk-spacing` must not be None")
    if not isinstance(params["yk-spacing"], (float, int)):
        raise StyxValidationError(f'`yk-spacing` has the wrong type: Received `{type(params.get("yk-spacing", None))}` expected `float`')
    if params.get("y-offset", None) is None:
        raise StyxValidationError("`y-offset` must not be None")
    if not isinstance(params["y-offset"], (float, int)):
        raise StyxValidationError(f'`y-offset` has the wrong type: Received `{type(params.get("y-offset", None))}` expected `float`')
    if params.get("zi-spacing", None) is None:
        raise StyxValidationError("`zi-spacing` must not be None")
    if not isinstance(params["zi-spacing"], (float, int)):
        raise StyxValidationError(f'`zi-spacing` has the wrong type: Received `{type(params.get("zi-spacing", None))}` expected `float`')
    if params.get("zj-spacing", None) is None:
        raise StyxValidationError("`zj-spacing` must not be None")
    if not isinstance(params["zj-spacing"], (float, int)):
        raise StyxValidationError(f'`zj-spacing` has the wrong type: Received `{type(params.get("zj-spacing", None))}` expected `float`')
    if params.get("zk-spacing", None) is None:
        raise StyxValidationError("`zk-spacing` must not be None")
    if not isinstance(params["zk-spacing"], (float, int)):
        raise StyxValidationError(f'`zk-spacing` has the wrong type: Received `{type(params.get("zk-spacing", None))}` expected `float`')
    if params.get("z-offset", None) is None:
        raise StyxValidationError("`z-offset` must not be None")
    if not isinstance(params["z-offset"], (float, int)):
        raise StyxValidationError(f'`z-offset` has the wrong type: Received `{type(params.get("z-offset", None))}` expected `float`')


def volume_create_sform_cargs(
    params: VolumeCreateSformParamsDict,
    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([
        "-sform",
        str(params.get("xi-spacing", None)),
        str(params.get("xj-spacing", None)),
        str(params.get("xk-spacing", None)),
        str(params.get("x-offset", None)),
        str(params.get("yi-spacing", None)),
        str(params.get("yj-spacing", None)),
        str(params.get("yk-spacing", None)),
        str(params.get("y-offset", None)),
        str(params.get("zi-spacing", None)),
        str(params.get("zj-spacing", None)),
        str(params.get("zk-spacing", None)),
        str(params.get("z-offset", None))
    ])
    return cargs


class VolumeCreateOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeCreateParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output volume"""


def volume_create_params(
    i_dim: int,
    j_dim: int,
    k_dim: int,
    volume_out: str,
    plumb: VolumeCreatePlumbParamsDict | None = None,
    sform: VolumeCreateSformParamsDict | None = None,
) -> VolumeCreateParamsDictTagged:
    """
    Build parameters.
    
    Args:
        i_dim: length of first dimension.
        j_dim: length of second dimension.
        k_dim: length of third dimension.
        volume_out: the output volume.
        plumb: set via axis order and spacing/offset.
        sform: set via a nifti sform.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-create",
        "i-dim": i_dim,
        "j-dim": j_dim,
        "k-dim": k_dim,
        "volume-out": volume_out,
    }
    if plumb is not None:
        params["plumb"] = plumb
    if sform is not None:
        params["sform"] = sform
    return params


def volume_create_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `VolumeCreateParamsDict` 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("i-dim", None) is None:
        raise StyxValidationError("`i-dim` must not be None")
    if not isinstance(params["i-dim"], int):
        raise StyxValidationError(f'`i-dim` has the wrong type: Received `{type(params.get("i-dim", None))}` expected `int`')
    if params.get("j-dim", None) is None:
        raise StyxValidationError("`j-dim` must not be None")
    if not isinstance(params["j-dim"], int):
        raise StyxValidationError(f'`j-dim` has the wrong type: Received `{type(params.get("j-dim", None))}` expected `int`')
    if params.get("k-dim", None) is None:
        raise StyxValidationError("`k-dim` must not be None")
    if not isinstance(params["k-dim"], int):
        raise StyxValidationError(f'`k-dim` has the wrong type: Received `{type(params.get("k-dim", None))}` expected `int`')
    if params.get("volume-out", None) is None:
        raise StyxValidationError("`volume-out` must not be None")
    if not isinstance(params["volume-out"], str):
        raise StyxValidationError(f'`volume-out` has the wrong type: Received `{type(params.get("volume-out", None))}` expected `str`')
    if params.get("plumb", None) is not None:
        volume_create_plumb_validate(params["plumb"])
    if params.get("sform", None) is not None:
        volume_create_sform_validate(params["sform"])


def volume_create_cargs(
    params: VolumeCreateParamsDict,
    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-create"
    ])
    cargs.append(str(params.get("i-dim", None)))
    cargs.append(str(params.get("j-dim", None)))
    cargs.append(str(params.get("k-dim", None)))
    cargs.append(params.get("volume-out", None))
    if params.get("plumb", None) is not None or params.get("sform", None) is not None:
        cargs.extend([
            *(volume_create_plumb_cargs(params.get("plumb", None), execution) if (params.get("plumb", None) is not None) else []),
            *(volume_create_sform_cargs(params.get("sform", None), execution) if (params.get("sform", None) is not None) else [])
        ])
    return cargs


def volume_create_outputs(
    params: VolumeCreateParamsDict,
    execution: Execution,
) -> VolumeCreateOutputs:
    """
    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 = VolumeCreateOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume-out", None)),
    )
    return ret


def volume_create_execute(
    params: VolumeCreateParamsDict,
    runner: Runner | None = None,
) -> VolumeCreateOutputs:
    """
    CREATE A BLANK VOLUME FILE.
    
    Creates a volume file full of zeros. Exactly one of -plumb or -sform must be
    specified.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeCreateOutputs`).
    """
    volume_create_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_CREATE_METADATA)
    params = execution.params(params)
    cargs = volume_create_cargs(params, execution)
    ret = volume_create_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_create(
    i_dim: int,
    j_dim: int,
    k_dim: int,
    volume_out: str,
    plumb: VolumeCreatePlumbParamsDict | None = None,
    sform: VolumeCreateSformParamsDict | None = None,
    runner: Runner | None = None,
) -> VolumeCreateOutputs:
    """
    CREATE A BLANK VOLUME FILE.
    
    Creates a volume file full of zeros. Exactly one of -plumb or -sform must be
    specified.
    
    Args:
        i_dim: length of first dimension.
        j_dim: length of second dimension.
        k_dim: length of third dimension.
        volume_out: the output volume.
        plumb: set via axis order and spacing/offset.
        sform: set via a nifti sform.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeCreateOutputs`).
    """
    params = volume_create_params(
        i_dim=i_dim,
        j_dim=j_dim,
        k_dim=k_dim,
        volume_out=volume_out,
        plumb=plumb,
        sform=sform,
    )
    return volume_create_execute(params, runner)


__all__ = [
    "VOLUME_CREATE_METADATA",
    "VolumeCreateOutputs",
    "VolumeCreateParamsDict",
    "VolumeCreateParamsDictTagged",
    "VolumeCreatePlumbParamsDict",
    "VolumeCreatePlumbParamsDictTagged",
    "VolumeCreateSformParamsDict",
    "VolumeCreateSformParamsDictTagged",
    "volume_create",
    "volume_create_execute",
    "volume_create_params",
    "volume_create_plumb",
    "volume_create_sform",
]
