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

import typing
import pathlib
from styxdefs import *

SURFACE_CORTEX_LAYER_METADATA = Metadata(
    id="0a46e1e069f0f2907566d8c22a87a309eba5009b.boutiques",
    name="surface-cortex-layer",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


SurfaceCortexLayerParameters = typing.TypedDict('SurfaceCortexLayerParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/surface-cortex-layer"]],
    "white_surface": InputPathType,
    "pial_surface": InputPathType,
    "location": float,
    "out_surface": str,
    "opt_placement_out_placement_metric": typing.NotRequired[str | None],
})
SurfaceCortexLayerParametersTagged = typing.TypedDict('SurfaceCortexLayerParametersTagged', {
    "@type": typing.Literal["workbench/surface-cortex-layer"],
    "white_surface": InputPathType,
    "pial_surface": InputPathType,
    "location": float,
    "out_surface": str,
    "opt_placement_out_placement_metric": typing.NotRequired[str | None],
})


class SurfaceCortexLayerOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCortexLayerParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_surface: OutputPathType
    """the output surface"""
    opt_placement_out_placement_metric: OutputPathType | None
    """output the placement as a volume fraction from pial to white: output
    metric"""


def surface_cortex_layer_params(
    white_surface: InputPathType,
    pial_surface: InputPathType,
    location: float,
    out_surface: str,
    opt_placement_out_placement_metric: str | None = None,
) -> SurfaceCortexLayerParametersTagged:
    """
    Build parameters.
    
    Args:
        white_surface: the white matter surface.
        pial_surface: the pial surface.
        location: what volume fraction to place the layer at.
        out_surface: the output surface.
        opt_placement_out_placement_metric: output the placement as a volume\
            fraction from pial to white: output metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-cortex-layer",
        "white_surface": white_surface,
        "pial_surface": pial_surface,
        "location": location,
        "out_surface": out_surface,
    }
    if opt_placement_out_placement_metric is not None:
        params["opt_placement_out_placement_metric"] = opt_placement_out_placement_metric
    return params


def surface_cortex_layer_cargs(
    params: SurfaceCortexLayerParameters,
    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("-surface-cortex-layer")
    cargs.append(execution.input_file(params.get("white_surface", None)))
    cargs.append(execution.input_file(params.get("pial_surface", None)))
    cargs.append(str(params.get("location", None)))
    cargs.append(params.get("out_surface", None))
    if params.get("opt_placement_out_placement_metric", None) is not None:
        cargs.extend([
            "-placement-out",
            params.get("opt_placement_out_placement_metric", None)
        ])
    return cargs


def surface_cortex_layer_outputs(
    params: SurfaceCortexLayerParameters,
    execution: Execution,
) -> SurfaceCortexLayerOutputs:
    """
    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 = SurfaceCortexLayerOutputs(
        root=execution.output_file("."),
        out_surface=execution.output_file(params.get("out_surface", None)),
        opt_placement_out_placement_metric=execution.output_file(params.get("opt_placement_out_placement_metric", None)) if (params.get("opt_placement_out_placement_metric") is not None) else None,
    )
    return ret


def surface_cortex_layer_execute(
    params: SurfaceCortexLayerParameters,
    runner: Runner | None = None,
) -> SurfaceCortexLayerOutputs:
    """
    surface-cortex-layer
    
    Create surface approximating a cortical layer.
    
    The input surfaces must have vertex correspondence. The output surface is
    generated by placing vertices between the two surfaces such that the
    enclosed volume within any small patch of the new and white surfaces is the
    given fraction of the volume of the same patch between the pial and white
    surfaces (i.e., specifying 0 would give the white surface, 1 would give the
    pial surface). .
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCortexLayerOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_CORTEX_LAYER_METADATA)
    params = execution.params(params)
    cargs = surface_cortex_layer_cargs(params, execution)
    ret = surface_cortex_layer_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_cortex_layer(
    white_surface: InputPathType,
    pial_surface: InputPathType,
    location: float,
    out_surface: str,
    opt_placement_out_placement_metric: str | None = None,
    runner: Runner | None = None,
) -> SurfaceCortexLayerOutputs:
    """
    surface-cortex-layer
    
    Create surface approximating a cortical layer.
    
    The input surfaces must have vertex correspondence. The output surface is
    generated by placing vertices between the two surfaces such that the
    enclosed volume within any small patch of the new and white surfaces is the
    given fraction of the volume of the same patch between the pial and white
    surfaces (i.e., specifying 0 would give the white surface, 1 would give the
    pial surface). .
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        white_surface: the white matter surface.
        pial_surface: the pial surface.
        location: what volume fraction to place the layer at.
        out_surface: the output surface.
        opt_placement_out_placement_metric: output the placement as a volume\
            fraction from pial to white: output metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCortexLayerOutputs`).
    """
    params = surface_cortex_layer_params(
        white_surface=white_surface,
        pial_surface=pial_surface,
        location=location,
        out_surface=out_surface,
        opt_placement_out_placement_metric=opt_placement_out_placement_metric,
    )
    return surface_cortex_layer_execute(params, runner)


__all__ = [
    "SURFACE_CORTEX_LAYER_METADATA",
    "SurfaceCortexLayerOutputs",
    "surface_cortex_layer",
    "surface_cortex_layer_execute",
    "surface_cortex_layer_params",
]
