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

import typing
import pathlib
from styxdefs import *

CONVERT_SCALAR_IMAGE_TO_RGB_METADATA = Metadata(
    id="0188f81662be3b550786a9a91112208db37eb27b.boutiques",
    name="ConvertScalarImageToRGB",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_ConvertScalarImageToRgbParamsDictNoTag = typing.TypedDict('_ConvertScalarImageToRgbParamsDictNoTag', {
    "image_dimension": int,
    "input_image": InputPathType,
    "output_image": str,
    "mask": InputPathType,
    "colormap": typing.Literal["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"],
    "custom_colormap_file": typing.NotRequired[InputPathType | None],
    "minimum_input": typing.NotRequired[float | None],
    "maximum_input": typing.NotRequired[float | None],
    "minimum_rgb_output": typing.NotRequired[int | None],
    "maximum_rgb_output": typing.NotRequired[int | None],
    "vtk_lookup_table": typing.NotRequired[str | None],
})
ConvertScalarImageToRgbParamsDictTagged = typing.TypedDict('ConvertScalarImageToRgbParamsDictTagged', {
    "@type": typing.Literal["ants/ConvertScalarImageToRGB"],
    "image_dimension": int,
    "input_image": InputPathType,
    "output_image": str,
    "mask": InputPathType,
    "colormap": typing.Literal["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"],
    "custom_colormap_file": typing.NotRequired[InputPathType | None],
    "minimum_input": typing.NotRequired[float | None],
    "maximum_input": typing.NotRequired[float | None],
    "minimum_rgb_output": typing.NotRequired[int | None],
    "maximum_rgb_output": typing.NotRequired[int | None],
    "vtk_lookup_table": typing.NotRequired[str | None],
})
ConvertScalarImageToRgbParamsDict = _ConvertScalarImageToRgbParamsDictNoTag | ConvertScalarImageToRgbParamsDictTagged


class ConvertScalarImageToRgbOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ConvertScalarImageToRgbParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_rgb_image: OutputPathType
    """The resulting RGB image after conversion."""


def convert_scalar_image_to_rgb_params(
    image_dimension: int,
    input_image: InputPathType,
    output_image: str,
    mask: InputPathType,
    colormap: typing.Literal["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"],
    custom_colormap_file: InputPathType | None = None,
    minimum_input: float | None = None,
    maximum_input: float | None = None,
    minimum_rgb_output: int | None = None,
    maximum_rgb_output: int | None = None,
    vtk_lookup_table: str | None = None,
) -> ConvertScalarImageToRgbParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_dimension: The dimensionality of the image (e.g., 2D or 3D).
        input_image: The input scalar image to be converted to RGB.
        output_image: The output RGB image file.
        mask: The mask image to apply during conversion.
        colormap: The colormap to use for RGB conversion.
        custom_colormap_file: The file specifying the custom colormap (only\
            used if colormap is 'custom').
        minimum_input: The minimum input value for scaling.
        maximum_input: The maximum input value for scaling.
        minimum_rgb_output: The minimum output value for the RGB image.\
            Defaults to 0.
        maximum_rgb_output: The maximum output value for the RGB image.\
            Defaults to 255.
        vtk_lookup_table: The VTK lookup table to apply for additional\
            customization.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ConvertScalarImageToRGB",
        "image_dimension": image_dimension,
        "input_image": input_image,
        "output_image": output_image,
        "mask": mask,
        "colormap": colormap,
    }
    if custom_colormap_file is not None:
        params["custom_colormap_file"] = custom_colormap_file
    if minimum_input is not None:
        params["minimum_input"] = minimum_input
    if maximum_input is not None:
        params["maximum_input"] = maximum_input
    if minimum_rgb_output is not None:
        params["minimum_rgb_output"] = minimum_rgb_output
    if maximum_rgb_output is not None:
        params["maximum_rgb_output"] = maximum_rgb_output
    if vtk_lookup_table is not None:
        params["vtk_lookup_table"] = vtk_lookup_table
    return params


def convert_scalar_image_to_rgb_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConvertScalarImageToRgbParamsDict` 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("image_dimension", None) is None:
        raise StyxValidationError("`image_dimension` must not be None")
    if not isinstance(params["image_dimension"], int):
        raise StyxValidationError(f'`image_dimension` has the wrong type: Received `{type(params.get("image_dimension", None))}` expected `int`')
    if params.get("input_image", None) is None:
        raise StyxValidationError("`input_image` must not be None")
    if not isinstance(params["input_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input_image` has the wrong type: Received `{type(params.get("input_image", None))}` expected `InputPathType`')
    if params.get("output_image", None) is None:
        raise StyxValidationError("`output_image` must not be None")
    if not isinstance(params["output_image"], str):
        raise StyxValidationError(f'`output_image` has the wrong type: Received `{type(params.get("output_image", None))}` expected `str`')
    if params.get("mask", None) is None:
        raise StyxValidationError("`mask` must not be None")
    if not isinstance(params["mask"], (pathlib.Path, str)):
        raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType`')
    if params.get("colormap", None) is None:
        raise StyxValidationError("`colormap` must not be None")
    if not isinstance(params["colormap"], str):
        raise StyxValidationError(f'`colormap` has the wrong type: Received `{type(params.get("colormap", None))}` expected `typing.Literal["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"]`')
    if params["colormap"] not in ["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"]:
        raise StyxValidationError("Parameter `colormap` must be one of [\"grey\", \"red\", \"green\", \"blue\", \"copper\", \"jet\", \"hsv\", \"spring\", \"summer\", \"autumn\", \"winter\", \"hot\", \"cool\", \"overunder\", \"custom\"]")
    if params.get("custom_colormap_file", None) is not None:
        if not isinstance(params["custom_colormap_file"], (pathlib.Path, str)):
            raise StyxValidationError(f'`custom_colormap_file` has the wrong type: Received `{type(params.get("custom_colormap_file", None))}` expected `InputPathType | None`')
    if params.get("minimum_input", None) is not None:
        if not isinstance(params["minimum_input"], (float, int)):
            raise StyxValidationError(f'`minimum_input` has the wrong type: Received `{type(params.get("minimum_input", None))}` expected `float | None`')
    if params.get("maximum_input", None) is not None:
        if not isinstance(params["maximum_input"], (float, int)):
            raise StyxValidationError(f'`maximum_input` has the wrong type: Received `{type(params.get("maximum_input", None))}` expected `float | None`')
    if params.get("minimum_rgb_output", None) is not None:
        if not isinstance(params["minimum_rgb_output"], int):
            raise StyxValidationError(f'`minimum_rgb_output` has the wrong type: Received `{type(params.get("minimum_rgb_output", None))}` expected `int | None`')
    if params.get("maximum_rgb_output", None) is not None:
        if not isinstance(params["maximum_rgb_output"], int):
            raise StyxValidationError(f'`maximum_rgb_output` has the wrong type: Received `{type(params.get("maximum_rgb_output", None))}` expected `int | None`')
    if params.get("vtk_lookup_table", None) is not None:
        if not isinstance(params["vtk_lookup_table"], str):
            raise StyxValidationError(f'`vtk_lookup_table` has the wrong type: Received `{type(params.get("vtk_lookup_table", None))}` expected `str | None`')


def convert_scalar_image_to_rgb_cargs(
    params: ConvertScalarImageToRgbParamsDict,
    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("ConvertScalarImageToRGB")
    cargs.append(str(params.get("image_dimension", None)))
    cargs.append(execution.input_file(params.get("input_image", None)))
    cargs.append(params.get("output_image", None))
    cargs.append(execution.input_file(params.get("mask", None)))
    cargs.append(params.get("colormap", None))
    if params.get("custom_colormap_file", None) is not None:
        cargs.append(execution.input_file(params.get("custom_colormap_file", None)))
    if params.get("minimum_input", None) is not None:
        cargs.append(str(params.get("minimum_input", None)))
    if params.get("maximum_input", None) is not None:
        cargs.append(str(params.get("maximum_input", None)))
    if params.get("minimum_rgb_output", None) is not None:
        cargs.append(str(params.get("minimum_rgb_output", None)))
    if params.get("maximum_rgb_output", None) is not None:
        cargs.append(str(params.get("maximum_rgb_output", None)))
    if params.get("vtk_lookup_table", None) is not None:
        cargs.append(params.get("vtk_lookup_table", None))
    return cargs


def convert_scalar_image_to_rgb_outputs(
    params: ConvertScalarImageToRgbParamsDict,
    execution: Execution,
) -> ConvertScalarImageToRgbOutputs:
    """
    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 = ConvertScalarImageToRgbOutputs(
        root=execution.output_file("."),
        output_rgb_image=execution.output_file(params.get("output_image", None)),
    )
    return ret


def convert_scalar_image_to_rgb_execute(
    params: ConvertScalarImageToRgbParamsDict,
    runner: Runner | None = None,
) -> ConvertScalarImageToRgbOutputs:
    """
    ConvertScalarImageToRGB
    
    Converts a scalar image to an RGB image using specified parameters. Supports
    multiple colormap options and customization.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertScalarImageToRgbOutputs`).
    """
    convert_scalar_image_to_rgb_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONVERT_SCALAR_IMAGE_TO_RGB_METADATA)
    params = execution.params(params)
    cargs = convert_scalar_image_to_rgb_cargs(params, execution)
    ret = convert_scalar_image_to_rgb_outputs(params, execution)
    execution.run(cargs)
    return ret


def convert_scalar_image_to_rgb(
    image_dimension: int,
    input_image: InputPathType,
    output_image: str,
    mask: InputPathType,
    colormap: typing.Literal["grey", "red", "green", "blue", "copper", "jet", "hsv", "spring", "summer", "autumn", "winter", "hot", "cool", "overunder", "custom"],
    custom_colormap_file: InputPathType | None = None,
    minimum_input: float | None = None,
    maximum_input: float | None = None,
    minimum_rgb_output: int | None = None,
    maximum_rgb_output: int | None = None,
    vtk_lookup_table: str | None = None,
    runner: Runner | None = None,
) -> ConvertScalarImageToRgbOutputs:
    """
    ConvertScalarImageToRGB
    
    Converts a scalar image to an RGB image using specified parameters. Supports
    multiple colormap options and customization.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the image (e.g., 2D or 3D).
        input_image: The input scalar image to be converted to RGB.
        output_image: The output RGB image file.
        mask: The mask image to apply during conversion.
        colormap: The colormap to use for RGB conversion.
        custom_colormap_file: The file specifying the custom colormap (only\
            used if colormap is 'custom').
        minimum_input: The minimum input value for scaling.
        maximum_input: The maximum input value for scaling.
        minimum_rgb_output: The minimum output value for the RGB image.\
            Defaults to 0.
        maximum_rgb_output: The maximum output value for the RGB image.\
            Defaults to 255.
        vtk_lookup_table: The VTK lookup table to apply for additional\
            customization.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertScalarImageToRgbOutputs`).
    """
    params = convert_scalar_image_to_rgb_params(
        image_dimension=image_dimension,
        input_image=input_image,
        output_image=output_image,
        mask=mask,
        colormap=colormap,
        custom_colormap_file=custom_colormap_file,
        minimum_input=minimum_input,
        maximum_input=maximum_input,
        minimum_rgb_output=minimum_rgb_output,
        maximum_rgb_output=maximum_rgb_output,
        vtk_lookup_table=vtk_lookup_table,
    )
    return convert_scalar_image_to_rgb_execute(params, runner)


__all__ = [
    "CONVERT_SCALAR_IMAGE_TO_RGB_METADATA",
    "ConvertScalarImageToRgbOutputs",
    "ConvertScalarImageToRgbParamsDict",
    "ConvertScalarImageToRgbParamsDictTagged",
    "convert_scalar_image_to_rgb",
    "convert_scalar_image_to_rgb_execute",
    "convert_scalar_image_to_rgb_params",
]
