# 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="5c246decade01d0e869276d986b6a0431ecb382d.boutiques",
    name="metric-convert",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricConvertToNiftiParameters = typing.TypedDict('MetricConvertToNiftiParameters', {
    "@type": typing.NotRequired[typing.Literal["to_nifti"]],
    "metric_in": InputPathType,
    "nifti_out": str,
})
MetricConvertToNiftiParametersTagged = typing.TypedDict('MetricConvertToNiftiParametersTagged', {
    "@type": typing.Literal["to_nifti"],
    "metric_in": InputPathType,
    "nifti_out": str,
})


MetricConvertFromNiftiParameters = typing.TypedDict('MetricConvertFromNiftiParameters', {
    "@type": typing.NotRequired[typing.Literal["from_nifti"]],
    "nifti_in": InputPathType,
    "surface_in": InputPathType,
    "metric_out": str,
})
MetricConvertFromNiftiParametersTagged = typing.TypedDict('MetricConvertFromNiftiParametersTagged', {
    "@type": typing.Literal["from_nifti"],
    "nifti_in": InputPathType,
    "surface_in": InputPathType,
    "metric_out": str,
})


MetricConvertParameters = typing.TypedDict('MetricConvertParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-convert"]],
    "to_nifti": typing.NotRequired[MetricConvertToNiftiParameters | None],
    "from_nifti": typing.NotRequired[MetricConvertFromNiftiParameters | None],
})
MetricConvertParametersTagged = typing.TypedDict('MetricConvertParametersTagged', {
    "@type": typing.Literal["workbench/metric-convert"],
    "to_nifti": typing.NotRequired[MetricConvertToNiftiParameters | None],
    "from_nifti": typing.NotRequired[MetricConvertFromNiftiParameters | None],
})


class MetricConvertToNiftiOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricConvertToNiftiParameters | 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_params(
    metric_in: InputPathType,
    nifti_out: str,
) -> MetricConvertToNiftiParametersTagged:
    """
    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_cargs(
    params: MetricConvertToNiftiParameters,
    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("-to-nifti")
    cargs.append(execution.input_file(params.get("metric_in", None)))
    cargs.append(params.get("nifti_out", None))
    return cargs


def metric_convert_to_nifti_outputs(
    params: MetricConvertToNiftiParameters,
    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 `MetricConvertFromNiftiParameters | 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_params(
    nifti_in: InputPathType,
    surface_in: InputPathType,
    metric_out: str,
) -> MetricConvertFromNiftiParametersTagged:
    """
    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_cargs(
    params: MetricConvertFromNiftiParameters,
    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("-from-nifti")
    cargs.append(execution.input_file(params.get("nifti_in", None)))
    cargs.append(execution.input_file(params.get("surface_in", None)))
    cargs.append(params.get("metric_out", None))
    return cargs


def metric_convert_from_nifti_outputs(
    params: MetricConvertFromNiftiParameters,
    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 `MetricConvertParameters(...)`.
    """
    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: MetricConvertToNiftiParameters | None = None,
    from_nifti: MetricConvertFromNiftiParameters | None = None,
) -> MetricConvertParametersTagged:
    """
    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_cargs(
    params: MetricConvertParameters,
    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("-metric-convert")
    if params.get("to_nifti", None) is not None:
        cargs.extend(metric_convert_to_nifti_cargs(params.get("to_nifti", None), execution))
    if params.get("from_nifti", None) is not None:
        cargs.extend(metric_convert_from_nifti_cargs(params.get("from_nifti", None), execution))
    return cargs


def metric_convert_outputs(
    params: MetricConvertParameters,
    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: MetricConvertParameters,
    runner: Runner | None = None,
) -> MetricConvertOutputs:
    """
    metric-convert
    
    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.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricConvertOutputs`).
    """
    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: MetricConvertToNiftiParameters | None = None,
    from_nifti: MetricConvertFromNiftiParameters | None = None,
    runner: Runner | None = None,
) -> MetricConvertOutputs:
    """
    metric-convert
    
    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.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    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",
    "MetricConvertOutputs",
    "MetricConvertToNiftiOutputs",
    "metric_convert",
    "metric_convert_execute",
    "metric_convert_from_nifti_params",
    "metric_convert_params",
    "metric_convert_to_nifti_params",
]
