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

import typing
import pathlib
from styxdefs import *

FILE_CONVERT_METADATA = Metadata(
    id="2ba9bfe538f65b507e6368c6504e85d0210593d5.boutiques",
    name="file-convert",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


FileConvertBorderVersionConvertParameters = typing.TypedDict('FileConvertBorderVersionConvertParameters', {
    "@type": typing.NotRequired[typing.Literal["border_version_convert"]],
    "border_in": InputPathType,
    "out_version": int,
    "border_out": str,
    "opt_surface_surface": typing.NotRequired[InputPathType | None],
})
FileConvertBorderVersionConvertParametersTagged = typing.TypedDict('FileConvertBorderVersionConvertParametersTagged', {
    "@type": typing.Literal["border_version_convert"],
    "border_in": InputPathType,
    "out_version": int,
    "border_out": str,
    "opt_surface_surface": typing.NotRequired[InputPathType | None],
})


FileConvertNiftiVersionConvertParameters = typing.TypedDict('FileConvertNiftiVersionConvertParameters', {
    "@type": typing.NotRequired[typing.Literal["nifti_version_convert"]],
    "input": str,
    "version": int,
    "output": str,
})
FileConvertNiftiVersionConvertParametersTagged = typing.TypedDict('FileConvertNiftiVersionConvertParametersTagged', {
    "@type": typing.Literal["nifti_version_convert"],
    "input": str,
    "version": int,
    "output": str,
})


FileConvertCiftiVersionConvertParameters = typing.TypedDict('FileConvertCiftiVersionConvertParameters', {
    "@type": typing.NotRequired[typing.Literal["cifti_version_convert"]],
    "cifti_in": InputPathType,
    "version": str,
    "cifti_out": str,
})
FileConvertCiftiVersionConvertParametersTagged = typing.TypedDict('FileConvertCiftiVersionConvertParametersTagged', {
    "@type": typing.Literal["cifti_version_convert"],
    "cifti_in": InputPathType,
    "version": str,
    "cifti_out": str,
})


FileConvertParameters = typing.TypedDict('FileConvertParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/file-convert"]],
    "border_version_convert": typing.NotRequired[FileConvertBorderVersionConvertParameters | None],
    "nifti_version_convert": typing.NotRequired[FileConvertNiftiVersionConvertParameters | None],
    "cifti_version_convert": typing.NotRequired[FileConvertCiftiVersionConvertParameters | None],
})
FileConvertParametersTagged = typing.TypedDict('FileConvertParametersTagged', {
    "@type": typing.Literal["workbench/file-convert"],
    "border_version_convert": typing.NotRequired[FileConvertBorderVersionConvertParameters | None],
    "nifti_version_convert": typing.NotRequired[FileConvertNiftiVersionConvertParameters | None],
    "cifti_version_convert": typing.NotRequired[FileConvertCiftiVersionConvertParameters | None],
})


def file_convert_border_version_convert_params(
    border_in: InputPathType,
    out_version: int,
    border_out: str,
    opt_surface_surface: InputPathType | None = None,
) -> FileConvertBorderVersionConvertParametersTagged:
    """
    Build parameters.
    
    Args:
        border_in: the input border file.
        out_version: the format version to write as, 1 or 3 (2 doesn't exist).
        border_out: output - the output border file.
        opt_surface_surface: must be specified if the input is version 1: use\
            this surface file for structure and number of vertices, ignore borders\
            on other structures.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "border_version_convert",
        "border_in": border_in,
        "out_version": out_version,
        "border_out": border_out,
    }
    if opt_surface_surface is not None:
        params["opt_surface_surface"] = opt_surface_surface
    return params


def file_convert_border_version_convert_cargs(
    params: FileConvertBorderVersionConvertParameters,
    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("-border-version-convert")
    cargs.append(execution.input_file(params.get("border_in", None)))
    cargs.append(str(params.get("out_version", None)))
    cargs.append(params.get("border_out", None))
    if params.get("opt_surface_surface", None) is not None:
        cargs.extend([
            "-surface",
            execution.input_file(params.get("opt_surface_surface", None))
        ])
    return cargs


def file_convert_nifti_version_convert_params(
    input_: str,
    version: int,
    output: str,
) -> FileConvertNiftiVersionConvertParametersTagged:
    """
    Build parameters.
    
    Args:
        input_: the input nifti file.
        version: the nifti version to write as.
        output: output - the output nifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "nifti_version_convert",
        "input": input_,
        "version": version,
        "output": output,
    }
    return params


def file_convert_nifti_version_convert_cargs(
    params: FileConvertNiftiVersionConvertParameters,
    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("-nifti-version-convert")
    cargs.append(params.get("input", None))
    cargs.append(str(params.get("version", None)))
    cargs.append(params.get("output", None))
    return cargs


def file_convert_cifti_version_convert_params(
    cifti_in: InputPathType,
    version: str,
    cifti_out: str,
) -> FileConvertCiftiVersionConvertParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the input cifti file.
        version: the cifti version to write as.
        cifti_out: output - the output cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cifti_version_convert",
        "cifti_in": cifti_in,
        "version": version,
        "cifti_out": cifti_out,
    }
    return params


def file_convert_cifti_version_convert_cargs(
    params: FileConvertCiftiVersionConvertParameters,
    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("-cifti-version-convert")
    cargs.append(execution.input_file(params.get("cifti_in", None)))
    cargs.append(params.get("version", None))
    cargs.append(params.get("cifti_out", None))
    return cargs


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


def file_convert_params(
    border_version_convert: FileConvertBorderVersionConvertParameters | None = None,
    nifti_version_convert: FileConvertNiftiVersionConvertParameters | None = None,
    cifti_version_convert: FileConvertCiftiVersionConvertParameters | None = None,
) -> FileConvertParametersTagged:
    """
    Build parameters.
    
    Args:
        border_version_convert: write a border file with a different version.
        nifti_version_convert: write a nifti file with a different version.
        cifti_version_convert: write a cifti file with a different version.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/file-convert",
    }
    if border_version_convert is not None:
        params["border_version_convert"] = border_version_convert
    if nifti_version_convert is not None:
        params["nifti_version_convert"] = nifti_version_convert
    if cifti_version_convert is not None:
        params["cifti_version_convert"] = cifti_version_convert
    return params


def file_convert_cargs(
    params: FileConvertParameters,
    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("wb_command")
    cargs.append("-file-convert")
    if params.get("border_version_convert", None) is not None:
        cargs.extend(file_convert_border_version_convert_cargs(params.get("border_version_convert", None), execution))
    if params.get("nifti_version_convert", None) is not None:
        cargs.extend(file_convert_nifti_version_convert_cargs(params.get("nifti_version_convert", None), execution))
    if params.get("cifti_version_convert", None) is not None:
        cargs.extend(file_convert_cifti_version_convert_cargs(params.get("cifti_version_convert", None), execution))
    return cargs


def file_convert_outputs(
    params: FileConvertParameters,
    execution: Execution,
) -> FileConvertOutputs:
    """
    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 = FileConvertOutputs(
        root=execution.output_file("."),
    )
    return ret


def file_convert_execute(
    params: FileConvertParameters,
    runner: Runner | None = None,
) -> FileConvertOutputs:
    """
    file-convert
    
    Change version of file format.
    
    You may only specify one top-level option.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FileConvertOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(FILE_CONVERT_METADATA)
    params = execution.params(params)
    cargs = file_convert_cargs(params, execution)
    ret = file_convert_outputs(params, execution)
    execution.run(cargs)
    return ret


def file_convert(
    border_version_convert: FileConvertBorderVersionConvertParameters | None = None,
    nifti_version_convert: FileConvertNiftiVersionConvertParameters | None = None,
    cifti_version_convert: FileConvertCiftiVersionConvertParameters | None = None,
    runner: Runner | None = None,
) -> FileConvertOutputs:
    """
    file-convert
    
    Change version of file format.
    
    You may only specify one top-level option.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        border_version_convert: write a border file with a different version.
        nifti_version_convert: write a nifti file with a different version.
        cifti_version_convert: write a cifti file with a different version.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FileConvertOutputs`).
    """
    params = file_convert_params(
        border_version_convert=border_version_convert,
        nifti_version_convert=nifti_version_convert,
        cifti_version_convert=cifti_version_convert,
    )
    return file_convert_execute(params, runner)


__all__ = [
    "FILE_CONVERT_METADATA",
    "FileConvertOutputs",
    "file_convert",
    "file_convert_border_version_convert_params",
    "file_convert_cifti_version_convert_params",
    "file_convert_execute",
    "file_convert_nifti_version_convert_params",
    "file_convert_params",
]
