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

import typing
import pathlib
from styxdefs import *

FOCI_LIST_COORDS_METADATA = Metadata(
    id="b16ceca59fb70119f927e417ec349a0afda6a816.workbench",
    name="foci-list-coords",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_FociListCoordsParamsDictNoTag = typing.TypedDict('_FociListCoordsParamsDictNoTag', {
    "foci-file": InputPathType,
    "coord-file-out": str,
    "names-file-out": typing.NotRequired[str | None],
})
FociListCoordsParamsDictTagged = typing.TypedDict('FociListCoordsParamsDictTagged', {
    "@type": typing.Literal["workbench/foci-list-coords"],
    "foci-file": InputPathType,
    "coord-file-out": str,
    "names-file-out": typing.NotRequired[str | None],
})
FociListCoordsParamsDict = _FociListCoordsParamsDictNoTag | FociListCoordsParamsDictTagged


class FociListCoordsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `FociListCoordsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def foci_list_coords_params(
    foci_file: InputPathType,
    coord_file_out: str,
    names_file_out: str | None = None,
) -> FociListCoordsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        foci_file: input foci file.
        coord_file_out: output - the output coordinate text file.
        names_file_out: output the foci names\
            \
            output - text file to put foci names in.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/foci-list-coords",
        "foci-file": foci_file,
        "coord-file-out": coord_file_out,
    }
    if names_file_out is not None:
        params["names-file-out"] = names_file_out
    return params


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


def foci_list_coords_cargs(
    params: FociListCoordsParamsDict,
    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",
        "-foci-list-coords"
    ])
    cargs.append(execution.input_file(params.get("foci-file", None)))
    cargs.append(params.get("coord-file-out", None))
    if params.get("names-file-out", None) is not None:
        cargs.extend([
            "-names-out",
            params.get("names-file-out", None)
        ])
    return cargs


def foci_list_coords_outputs(
    params: FociListCoordsParamsDict,
    execution: Execution,
) -> FociListCoordsOutputs:
    """
    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 = FociListCoordsOutputs(
        root=execution.output_file("."),
    )
    return ret


def foci_list_coords_execute(
    params: FociListCoordsParamsDict,
    runner: Runner | None = None,
) -> FociListCoordsOutputs:
    """
    OUTPUT FOCI COORDINATES IN A TEXT FILE.
    
    Output the coordinates for every focus in the foci file, and optionally the
    focus names in a second text file.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FociListCoordsOutputs`).
    """
    foci_list_coords_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(FOCI_LIST_COORDS_METADATA)
    params = execution.params(params)
    cargs = foci_list_coords_cargs(params, execution)
    ret = foci_list_coords_outputs(params, execution)
    execution.run(cargs)
    return ret


def foci_list_coords(
    foci_file: InputPathType,
    coord_file_out: str,
    names_file_out: str | None = None,
    runner: Runner | None = None,
) -> FociListCoordsOutputs:
    """
    OUTPUT FOCI COORDINATES IN A TEXT FILE.
    
    Output the coordinates for every focus in the foci file, and optionally the
    focus names in a second text file.
    
    Args:
        foci_file: input foci file.
        coord_file_out: output - the output coordinate text file.
        names_file_out: output the foci names\
            \
            output - text file to put foci names in.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FociListCoordsOutputs`).
    """
    params = foci_list_coords_params(
        foci_file=foci_file,
        coord_file_out=coord_file_out,
        names_file_out=names_file_out,
    )
    return foci_list_coords_execute(params, runner)


__all__ = [
    "FOCI_LIST_COORDS_METADATA",
    "FociListCoordsOutputs",
    "FociListCoordsParamsDict",
    "FociListCoordsParamsDictTagged",
    "foci_list_coords",
    "foci_list_coords_execute",
    "foci_list_coords_params",
]
