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

import typing
import pathlib
from styxdefs import *

METRIC_CONVERT_METADATA = Metadata(
    id="4df60d9d341bdad2b06cad65892590415be630ec.workbench",
    name="metric-convert",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_MetricConvertToNiftiParamsDictNoTag = typing.TypedDict('_MetricConvertToNiftiParamsDictNoTag', {
    "metric-in": InputPathType,
    "nifti-out": str,
})
MetricConvertToNiftiParamsDictTagged = typing.TypedDict('MetricConvertToNiftiParamsDictTagged', {
    "@type": typing.Literal["to-nifti"],
    "metric-in": InputPathType,
    "nifti-out": str,
})
MetricConvertToNiftiParamsDict = _MetricConvertToNiftiParamsDictNoTag | MetricConvertToNiftiParamsDictTagged


_MetricConvertFromNiftiParamsDictNoTag = typing.TypedDict('_MetricConvertFromNiftiParamsDictNoTag', {
    "nifti-in": InputPathType,
    "surface-in": InputPathType,
    "metric-out": str,
})
MetricConvertFromNiftiParamsDictTagged = typing.TypedDict('MetricConvertFromNiftiParamsDictTagged', {
    "@type": typing.Literal["from-nifti"],
    "nifti-in": InputPathType,
    "surface-in": InputPathType,
    "metric-out": str,
})
MetricConvertFromNiftiParamsDict = _MetricConvertFromNiftiParamsDictNoTag | MetricConvertFromNiftiParamsDictTagged


_MetricConvertParamsDictNoTag = typing.TypedDict('_MetricConvertParamsDictNoTag', {
    "to-nifti": typing.NotRequired[MetricConvertToNiftiParamsDict | None],
    "from-nifti": typing.NotRequired[MetricConvertFromNiftiParamsDict | None],
})
MetricConvertParamsDictTagged = typing.TypedDict('MetricConvertParamsDictTagged', {
    "@type": typing.Literal["workbench/metric-convert"],
    "to-nifti": typing.NotRequired[MetricConvertToNiftiParamsDict | None],
    "from-nifti": typing.NotRequired[MetricConvertFromNiftiParamsDict | None],
})
MetricConvertParamsDict = _MetricConvertParamsDictNoTag | MetricConvertParamsDictTagged


class MetricConvertToNiftiOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricConvertToNiftiParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    nifti_out: OutputPathType
    """the output nifti file"""


def metric_convert_to_nifti(
    metric_in: InputPathType,
    nifti_out: str,
) -> MetricConvertToNiftiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        metric_in: the metric to convert.
        nifti_out: the output nifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "to-nifti",
        "metric-in": metric_in,
        "nifti-out": nifti_out,
    }
    return params


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


def metric_convert_to_nifti_cargs(
    params: MetricConvertToNiftiParamsDict,
    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([
        "-to-nifti",
        execution.input_file(params.get("metric-in", None)),
        params.get("nifti-out", None)
    ])
    return cargs


def metric_convert_to_nifti_outputs(
    params: MetricConvertToNiftiParamsDict,
    execution: Execution,
) -> MetricConvertToNiftiOutputs:
    """
    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 = MetricConvertToNiftiOutputs(
        root=execution.output_file("."),
        nifti_out=execution.output_file(params.get("nifti-out", None)),
    )
    return ret


class MetricConvertFromNiftiOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricConvertFromNiftiParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output metric file"""


def metric_convert_from_nifti(
    nifti_in: InputPathType,
    surface_in: InputPathType,
    metric_out: str,
) -> MetricConvertFromNiftiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        nifti_in: the nifti file to convert.
        surface_in: surface file to use number of vertices and structure from.
        metric_out: the output metric file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "from-nifti",
        "nifti-in": nifti_in,
        "surface-in": surface_in,
        "metric-out": metric_out,
    }
    return params


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


def metric_convert_from_nifti_cargs(
    params: MetricConvertFromNiftiParamsDict,
    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([
        "-from-nifti",
        execution.input_file(params.get("nifti-in", None)),
        execution.input_file(params.get("surface-in", None)),
        params.get("metric-out", None)
    ])
    return cargs


def metric_convert_from_nifti_outputs(
    params: MetricConvertFromNiftiParamsDict,
    execution: Execution,
) -> MetricConvertFromNiftiOutputs:
    """
    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 = MetricConvertFromNiftiOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric-out", None)),
    )
    return ret


class MetricConvertOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricConvertParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    to_nifti: MetricConvertToNiftiOutputs | None
    """Outputs from `metric_convert_to_nifti_outputs`."""
    from_nifti: MetricConvertFromNiftiOutputs | None
    """Outputs from `metric_convert_from_nifti_outputs`."""


def metric_convert_params(
    to_nifti: MetricConvertToNiftiParamsDict | None = None,
    from_nifti: MetricConvertFromNiftiParamsDict | None = None,
) -> MetricConvertParamsDictTagged:
    """
    Build parameters.
    
    Args:
        to_nifti: convert metric to nifti.
        from_nifti: convert nifti to metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-convert",
    }
    if to_nifti is not None:
        params["to-nifti"] = to_nifti
    if from_nifti is not None:
        params["from-nifti"] = from_nifti
    return params


def metric_convert_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MetricConvertParamsDict` 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("to-nifti", None) is not None:
        metric_convert_to_nifti_validate(params["to-nifti"])
    if params.get("from-nifti", None) is not None:
        metric_convert_from_nifti_validate(params["from-nifti"])


def metric_convert_cargs(
    params: MetricConvertParamsDict,
    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",
        "-metric-convert"
    ])
    if params.get("to-nifti", None) is not None or params.get("from-nifti", None) is not None:
        cargs.extend([
            *(metric_convert_to_nifti_cargs(params.get("to-nifti", None), execution) if (params.get("to-nifti", None) is not None) else []),
            *(metric_convert_from_nifti_cargs(params.get("from-nifti", None), execution) if (params.get("from-nifti", None) is not None) else [])
        ])
    return cargs


def metric_convert_outputs(
    params: MetricConvertParamsDict,
    execution: Execution,
) -> MetricConvertOutputs:
    """
    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 = MetricConvertOutputs(
        root=execution.output_file("."),
        to_nifti=metric_convert_to_nifti_outputs(params.get("to-nifti"), execution) if params.get("to-nifti") else None,
        from_nifti=metric_convert_from_nifti_outputs(params.get("from-nifti"), execution) if params.get("from-nifti") else None,
    )
    return ret


def metric_convert_execute(
    params: MetricConvertParamsDict,
    runner: Runner | None = None,
) -> MetricConvertOutputs:
    """
    CONVERT METRIC FILE TO FAKE NIFTI.
    
    The purpose of this command is to convert between metric files and nifti1 so
    that gifti-unaware programs can operate on the data. You must specify
    exactly one of the options.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricConvertOutputs`).
    """
    metric_convert_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_CONVERT_METADATA)
    params = execution.params(params)
    cargs = metric_convert_cargs(params, execution)
    ret = metric_convert_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_convert(
    to_nifti: MetricConvertToNiftiParamsDict | None = None,
    from_nifti: MetricConvertFromNiftiParamsDict | None = None,
    runner: Runner | None = None,
) -> MetricConvertOutputs:
    """
    CONVERT METRIC FILE TO FAKE NIFTI.
    
    The purpose of this command is to convert between metric files and nifti1 so
    that gifti-unaware programs can operate on the data. You must specify
    exactly one of the options.
    
    Args:
        to_nifti: convert metric to nifti.
        from_nifti: convert nifti to metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricConvertOutputs`).
    """
    params = metric_convert_params(
        to_nifti=to_nifti,
        from_nifti=from_nifti,
    )
    return metric_convert_execute(params, runner)


__all__ = [
    "METRIC_CONVERT_METADATA",
    "MetricConvertFromNiftiOutputs",
    "MetricConvertFromNiftiParamsDict",
    "MetricConvertFromNiftiParamsDictTagged",
    "MetricConvertOutputs",
    "MetricConvertParamsDict",
    "MetricConvertParamsDictTagged",
    "MetricConvertToNiftiOutputs",
    "MetricConvertToNiftiParamsDict",
    "MetricConvertToNiftiParamsDictTagged",
    "metric_convert",
    "metric_convert_execute",
    "metric_convert_from_nifti",
    "metric_convert_params",
    "metric_convert_to_nifti",
]
