# 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="955bdf431ca1cccbf73a19afbeac8667fbb4a28c.workbench",
    name="file-convert",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_FileConvertBorderVersionConvertParamsDictNoTag = typing.TypedDict('_FileConvertBorderVersionConvertParamsDictNoTag', {
    "border-in": InputPathType,
    "out-version": int,
    "border-out": str,
    "surface": typing.NotRequired[InputPathType | None],
})
FileConvertBorderVersionConvertParamsDictTagged = typing.TypedDict('FileConvertBorderVersionConvertParamsDictTagged', {
    "@type": typing.Literal["border-version-convert"],
    "border-in": InputPathType,
    "out-version": int,
    "border-out": str,
    "surface": typing.NotRequired[InputPathType | None],
})
FileConvertBorderVersionConvertParamsDict = _FileConvertBorderVersionConvertParamsDictNoTag | FileConvertBorderVersionConvertParamsDictTagged


_FileConvertNiftiVersionConvertParamsDictNoTag = typing.TypedDict('_FileConvertNiftiVersionConvertParamsDictNoTag', {
    "input": str,
    "version": int,
    "output": str,
})
FileConvertNiftiVersionConvertParamsDictTagged = typing.TypedDict('FileConvertNiftiVersionConvertParamsDictTagged', {
    "@type": typing.Literal["nifti-version-convert"],
    "input": str,
    "version": int,
    "output": str,
})
FileConvertNiftiVersionConvertParamsDict = _FileConvertNiftiVersionConvertParamsDictNoTag | FileConvertNiftiVersionConvertParamsDictTagged


_FileConvertCiftiVersionConvertParamsDictNoTag = typing.TypedDict('_FileConvertCiftiVersionConvertParamsDictNoTag', {
    "cifti-in": InputPathType,
    "version": str,
    "cifti-out": str,
})
FileConvertCiftiVersionConvertParamsDictTagged = typing.TypedDict('FileConvertCiftiVersionConvertParamsDictTagged', {
    "@type": typing.Literal["cifti-version-convert"],
    "cifti-in": InputPathType,
    "version": str,
    "cifti-out": str,
})
FileConvertCiftiVersionConvertParamsDict = _FileConvertCiftiVersionConvertParamsDictNoTag | FileConvertCiftiVersionConvertParamsDictTagged


_FileConvertParamsDictNoTag = typing.TypedDict('_FileConvertParamsDictNoTag', {
    "border-version-convert": typing.NotRequired[FileConvertBorderVersionConvertParamsDict | None],
    "nifti-version-convert": typing.NotRequired[FileConvertNiftiVersionConvertParamsDict | None],
    "cifti-version-convert": typing.NotRequired[FileConvertCiftiVersionConvertParamsDict | None],
})
FileConvertParamsDictTagged = typing.TypedDict('FileConvertParamsDictTagged', {
    "@type": typing.Literal["workbench/file-convert"],
    "border-version-convert": typing.NotRequired[FileConvertBorderVersionConvertParamsDict | None],
    "nifti-version-convert": typing.NotRequired[FileConvertNiftiVersionConvertParamsDict | None],
    "cifti-version-convert": typing.NotRequired[FileConvertCiftiVersionConvertParamsDict | None],
})
FileConvertParamsDict = _FileConvertParamsDictNoTag | FileConvertParamsDictTagged


def file_convert_border_version_convert(
    border_in: InputPathType,
    out_version: int,
    border_out: str,
    surface: InputPathType | None = None,
) -> FileConvertBorderVersionConvertParamsDictTagged:
    """
    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.
        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 surface is not None:
        params["surface"] = surface
    return params


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


def file_convert_border_version_convert_cargs(
    params: FileConvertBorderVersionConvertParamsDict,
    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([
        "-border-version-convert",
        execution.input_file(params.get("border-in", None)),
        str(params.get("out-version", None)),
        params.get("border-out", None)
    ])
    if params.get("surface", None) is not None:
        cargs.extend([
            "-surface",
            execution.input_file(params.get("surface", None))
        ])
    return cargs


def file_convert_nifti_version_convert(
    input_: str,
    version: int,
    output: str,
) -> FileConvertNiftiVersionConvertParamsDictTagged:
    """
    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_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FileConvertNiftiVersionConvertParamsDict` 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("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], str):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `str`')
    if params.get("version", None) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], int):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", None))}` expected `int`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')


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


def file_convert_cifti_version_convert(
    cifti_in: InputPathType,
    version: str,
    cifti_out: str,
) -> FileConvertCiftiVersionConvertParamsDictTagged:
    """
    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_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FileConvertCiftiVersionConvertParamsDict` 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("cifti-in", None) is None:
        raise StyxValidationError("`cifti-in` must not be None")
    if not isinstance(params["cifti-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-in` has the wrong type: Received `{type(params.get("cifti-in", None))}` expected `InputPathType`')
    if params.get("version", None) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], str):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", None))}` expected `str`')
    if params.get("cifti-out", None) is None:
        raise StyxValidationError("`cifti-out` must not be None")
    if not isinstance(params["cifti-out"], str):
        raise StyxValidationError(f'`cifti-out` has the wrong type: Received `{type(params.get("cifti-out", None))}` expected `str`')


def file_convert_cifti_version_convert_cargs(
    params: FileConvertCiftiVersionConvertParamsDict,
    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([
        "-cifti-version-convert",
        execution.input_file(params.get("cifti-in", None)),
        params.get("version", None),
        params.get("cifti-out", None)
    ])
    return cargs


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


def file_convert_params(
    border_version_convert: FileConvertBorderVersionConvertParamsDict | None = None,
    nifti_version_convert: FileConvertNiftiVersionConvertParamsDict | None = None,
    cifti_version_convert: FileConvertCiftiVersionConvertParamsDict | None = None,
) -> FileConvertParamsDictTagged:
    """
    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_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FileConvertParamsDict` 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("border-version-convert", None) is not None:
        file_convert_border_version_convert_validate(params["border-version-convert"])
    if params.get("nifti-version-convert", None) is not None:
        file_convert_nifti_version_convert_validate(params["nifti-version-convert"])
    if params.get("cifti-version-convert", None) is not None:
        file_convert_cifti_version_convert_validate(params["cifti-version-convert"])


def file_convert_cargs(
    params: FileConvertParamsDict,
    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",
        "-file-convert"
    ])
    if params.get("border-version-convert", None) is not None or params.get("nifti-version-convert", None) is not None or params.get("cifti-version-convert", None) is not None:
        cargs.extend([
            *(file_convert_border_version_convert_cargs(params.get("border-version-convert", None), execution) if (params.get("border-version-convert", None) is not None) else []),
            *(file_convert_nifti_version_convert_cargs(params.get("nifti-version-convert", None), execution) if (params.get("nifti-version-convert", None) is not None) else []),
            *(file_convert_cifti_version_convert_cargs(params.get("cifti-version-convert", None), execution) if (params.get("cifti-version-convert", None) is not None) else [])
        ])
    return cargs


def file_convert_outputs(
    params: FileConvertParamsDict,
    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: FileConvertParamsDict,
    runner: Runner | None = None,
) -> FileConvertOutputs:
    """
    CHANGE VERSION OF FILE FORMAT.
    
    You may only specify one top-level option.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FileConvertOutputs`).
    """
    file_convert_validate(params)
    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: FileConvertBorderVersionConvertParamsDict | None = None,
    nifti_version_convert: FileConvertNiftiVersionConvertParamsDict | None = None,
    cifti_version_convert: FileConvertCiftiVersionConvertParamsDict | None = None,
    runner: Runner | None = None,
) -> FileConvertOutputs:
    """
    CHANGE VERSION OF FILE FORMAT.
    
    You may only specify one top-level option.
    
    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",
    "FileConvertBorderVersionConvertParamsDict",
    "FileConvertBorderVersionConvertParamsDictTagged",
    "FileConvertCiftiVersionConvertParamsDict",
    "FileConvertCiftiVersionConvertParamsDictTagged",
    "FileConvertNiftiVersionConvertParamsDict",
    "FileConvertNiftiVersionConvertParamsDictTagged",
    "FileConvertOutputs",
    "FileConvertParamsDict",
    "FileConvertParamsDictTagged",
    "file_convert",
    "file_convert_border_version_convert",
    "file_convert_cifti_version_convert",
    "file_convert_execute",
    "file_convert_nifti_version_convert",
    "file_convert_params",
]
