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

import typing
import pathlib
from styxdefs import *

CONVERT_TO_JPG_METADATA = Metadata(
    id="05ba9d9a81340f45633926fc4c293fdf619a95ab.boutiques",
    name="ConvertToJpg",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_ConvertToJpgParamsDictNoTag = typing.TypedDict('_ConvertToJpgParamsDictNoTag', {
    "infile": InputPathType,
    "outfile": str,
})
ConvertToJpgParamsDictTagged = typing.TypedDict('ConvertToJpgParamsDictTagged', {
    "@type": typing.Literal["ants/ConvertToJpg"],
    "infile": InputPathType,
    "outfile": str,
})
ConvertToJpgParamsDict = _ConvertToJpgParamsDictNoTag | ConvertToJpgParamsDictTagged


class ConvertToJpgOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ConvertToJpgParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_jpg: OutputPathType
    """The converted JPG image."""


def convert_to_jpg_params(
    infile: InputPathType,
    outfile: str,
) -> ConvertToJpgParamsDictTagged:
    """
    Build parameters.
    
    Args:
        infile: The input file in NIfTI format.
        outfile: The output file in JPG format.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ConvertToJpg",
        "infile": infile,
        "outfile": outfile,
    }
    return params


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


def convert_to_jpg_cargs(
    params: ConvertToJpgParamsDict,
    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("ConvertToJpg")
    cargs.append(execution.input_file(params.get("infile", None)))
    cargs.append(params.get("outfile", None))
    return cargs


def convert_to_jpg_outputs(
    params: ConvertToJpgParamsDict,
    execution: Execution,
) -> ConvertToJpgOutputs:
    """
    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 = ConvertToJpgOutputs(
        root=execution.output_file("."),
        output_jpg=execution.output_file(params.get("outfile", None)),
    )
    return ret


def convert_to_jpg_execute(
    params: ConvertToJpgParamsDict,
    runner: Runner | None = None,
) -> ConvertToJpgOutputs:
    """
    ConvertToJpg
    
    A tool to convert NIfTI images to JPG format.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertToJpgOutputs`).
    """
    convert_to_jpg_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONVERT_TO_JPG_METADATA)
    params = execution.params(params)
    cargs = convert_to_jpg_cargs(params, execution)
    ret = convert_to_jpg_outputs(params, execution)
    execution.run(cargs)
    return ret


def convert_to_jpg(
    infile: InputPathType,
    outfile: str,
    runner: Runner | None = None,
) -> ConvertToJpgOutputs:
    """
    ConvertToJpg
    
    A tool to convert NIfTI images to JPG format.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        infile: The input file in NIfTI format.
        outfile: The output file in JPG format.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertToJpgOutputs`).
    """
    params = convert_to_jpg_params(
        infile=infile,
        outfile=outfile,
    )
    return convert_to_jpg_execute(params, runner)


__all__ = [
    "CONVERT_TO_JPG_METADATA",
    "ConvertToJpgOutputs",
    "ConvertToJpgParamsDict",
    "ConvertToJpgParamsDictTagged",
    "convert_to_jpg",
    "convert_to_jpg_execute",
    "convert_to_jpg_params",
]
