# 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="1f7274373b18590446afbc6e9b2ac5914d86c611.workbench",
    name="surface-cortex-layer",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceCortexLayerPlacementOutParamsDictNoTag = typing.TypedDict('_SurfaceCortexLayerPlacementOutParamsDictNoTag', {
    "placement-metric": str,
})
SurfaceCortexLayerPlacementOutParamsDictTagged = typing.TypedDict('SurfaceCortexLayerPlacementOutParamsDictTagged', {
    "@type": typing.Literal["placement-out"],
    "placement-metric": str,
})
SurfaceCortexLayerPlacementOutParamsDict = _SurfaceCortexLayerPlacementOutParamsDictNoTag | SurfaceCortexLayerPlacementOutParamsDictTagged


_SurfaceCortexLayerParamsDictNoTag = typing.TypedDict('_SurfaceCortexLayerParamsDictNoTag', {
    "white-surface": InputPathType,
    "pial-surface": InputPathType,
    "location": float,
    "out-surface": str,
    "placement-out": typing.NotRequired[SurfaceCortexLayerPlacementOutParamsDict | None],
})
SurfaceCortexLayerParamsDictTagged = typing.TypedDict('SurfaceCortexLayerParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-cortex-layer"],
    "white-surface": InputPathType,
    "pial-surface": InputPathType,
    "location": float,
    "out-surface": str,
    "placement-out": typing.NotRequired[SurfaceCortexLayerPlacementOutParamsDict | None],
})
SurfaceCortexLayerParamsDict = _SurfaceCortexLayerParamsDictNoTag | SurfaceCortexLayerParamsDictTagged


class SurfaceCortexLayerPlacementOutOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCortexLayerPlacementOutParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    placement_metric: OutputPathType
    """output metric"""


def surface_cortex_layer_placement_out(
    placement_metric: str,
) -> SurfaceCortexLayerPlacementOutParamsDictTagged:
    """
    Build parameters.
    
    Args:
        placement_metric: output metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "placement-out",
        "placement-metric": placement_metric,
    }
    return params


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


def surface_cortex_layer_placement_out_cargs(
    params: SurfaceCortexLayerPlacementOutParamsDict,
    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([
        "-placement-out",
        params.get("placement-metric", None)
    ])
    return cargs


def surface_cortex_layer_placement_out_outputs(
    params: SurfaceCortexLayerPlacementOutParamsDict,
    execution: Execution,
) -> SurfaceCortexLayerPlacementOutOutputs:
    """
    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 = SurfaceCortexLayerPlacementOutOutputs(
        root=execution.output_file("."),
        placement_metric=execution.output_file(params.get("placement-metric", None)),
    )
    return ret


class SurfaceCortexLayerOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCortexLayerParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_surface: OutputPathType
    """the output surface"""
    placement_out: SurfaceCortexLayerPlacementOutOutputs | None
    """Outputs from `surface_cortex_layer_placement_out_outputs`."""


def surface_cortex_layer_params(
    white_surface: InputPathType,
    pial_surface: InputPathType,
    location: float,
    out_surface: str,
    placement_out: SurfaceCortexLayerPlacementOutParamsDict | None = None,
) -> SurfaceCortexLayerParamsDictTagged:
    """
    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.
        placement_out: output the placement as a volume fraction from pial to\
            white.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-cortex-layer",
        "white-surface": white_surface,
        "pial-surface": pial_surface,
        "location": location,
        "out-surface": out_surface,
    }
    if placement_out is not None:
        params["placement-out"] = placement_out
    return params


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


def surface_cortex_layer_cargs(
    params: SurfaceCortexLayerParamsDict,
    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",
        "-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("placement-out", None) is not None:
        cargs.extend(surface_cortex_layer_placement_out_cargs(params.get("placement-out", None), execution))
    return cargs


def surface_cortex_layer_outputs(
    params: SurfaceCortexLayerParamsDict,
    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)),
        placement_out=surface_cortex_layer_placement_out_outputs(params.get("placement-out"), execution) if params.get("placement-out") else None,
    )
    return ret


def surface_cortex_layer_execute(
    params: SurfaceCortexLayerParamsDict,
    runner: Runner | None = None,
) -> SurfaceCortexLayerOutputs:
    """
    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). .
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCortexLayerOutputs`).
    """
    surface_cortex_layer_validate(params)
    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,
    placement_out: SurfaceCortexLayerPlacementOutParamsDict | None = None,
    runner: Runner | None = None,
) -> SurfaceCortexLayerOutputs:
    """
    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). .
    
    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.
        placement_out: output the placement as a volume fraction from pial to\
            white.
        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,
        placement_out=placement_out,
    )
    return surface_cortex_layer_execute(params, runner)


__all__ = [
    "SURFACE_CORTEX_LAYER_METADATA",
    "SurfaceCortexLayerOutputs",
    "SurfaceCortexLayerParamsDict",
    "SurfaceCortexLayerParamsDictTagged",
    "SurfaceCortexLayerPlacementOutOutputs",
    "SurfaceCortexLayerPlacementOutParamsDict",
    "SurfaceCortexLayerPlacementOutParamsDictTagged",
    "surface_cortex_layer",
    "surface_cortex_layer_execute",
    "surface_cortex_layer_params",
    "surface_cortex_layer_placement_out",
]
