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

import typing
import pathlib
from styxdefs import *

METADATA_STRING_REPLACE_METADATA = Metadata(
    id="64839919f0abce1435877772c78bd57e1db01436.boutiques",
    name="metadata-string-replace",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetadataStringReplaceParameters = typing.TypedDict('MetadataStringReplaceParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metadata-string-replace"]],
    "input_file": str,
    "find_string": str,
    "replace_string": str,
    "output_file": str,
    "opt_case_insensitive": bool,
})
MetadataStringReplaceParametersTagged = typing.TypedDict('MetadataStringReplaceParametersTagged', {
    "@type": typing.Literal["workbench/metadata-string-replace"],
    "input_file": str,
    "find_string": str,
    "replace_string": str,
    "output_file": str,
    "opt_case_insensitive": bool,
})


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


def metadata_string_replace_params(
    input_file: str,
    find_string: str,
    replace_string: str,
    output_file: str,
    opt_case_insensitive: bool = False,
) -> MetadataStringReplaceParametersTagged:
    """
    Build parameters.
    
    Args:
        input_file: the file to replace metadata in.
        find_string: the string to find.
        replace_string: the string to replace <find-string> with.
        output_file: output - the name to save the modified file as.
        opt_case_insensitive: match with case variation also.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metadata-string-replace",
        "input_file": input_file,
        "find_string": find_string,
        "replace_string": replace_string,
        "output_file": output_file,
        "opt_case_insensitive": opt_case_insensitive,
    }
    return params


def metadata_string_replace_cargs(
    params: MetadataStringReplaceParameters,
    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("-metadata-string-replace")
    cargs.append(params.get("input_file", None))
    cargs.append(params.get("find_string", None))
    cargs.append(params.get("replace_string", None))
    cargs.append(params.get("output_file", None))
    if params.get("opt_case_insensitive", False):
        cargs.append("-case-insensitive")
    return cargs


def metadata_string_replace_outputs(
    params: MetadataStringReplaceParameters,
    execution: Execution,
) -> MetadataStringReplaceOutputs:
    """
    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 = MetadataStringReplaceOutputs(
        root=execution.output_file("."),
    )
    return ret


def metadata_string_replace_execute(
    params: MetadataStringReplaceParameters,
    runner: Runner | None = None,
) -> MetadataStringReplaceOutputs:
    """
    metadata-string-replace
    
    Replace a string in all metadata of a file.
    
    Replaces all occurrences of <find-string> in the metadata and map names of
    <input-file> with <replace-string>.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetadataStringReplaceOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METADATA_STRING_REPLACE_METADATA)
    params = execution.params(params)
    cargs = metadata_string_replace_cargs(params, execution)
    ret = metadata_string_replace_outputs(params, execution)
    execution.run(cargs)
    return ret


def metadata_string_replace(
    input_file: str,
    find_string: str,
    replace_string: str,
    output_file: str,
    opt_case_insensitive: bool = False,
    runner: Runner | None = None,
) -> MetadataStringReplaceOutputs:
    """
    metadata-string-replace
    
    Replace a string in all metadata of a file.
    
    Replaces all occurrences of <find-string> in the metadata and map names of
    <input-file> with <replace-string>.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        input_file: the file to replace metadata in.
        find_string: the string to find.
        replace_string: the string to replace <find-string> with.
        output_file: output - the name to save the modified file as.
        opt_case_insensitive: match with case variation also.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetadataStringReplaceOutputs`).
    """
    params = metadata_string_replace_params(
        input_file=input_file,
        find_string=find_string,
        replace_string=replace_string,
        output_file=output_file,
        opt_case_insensitive=opt_case_insensitive,
    )
    return metadata_string_replace_execute(params, runner)


__all__ = [
    "METADATA_STRING_REPLACE_METADATA",
    "MetadataStringReplaceOutputs",
    "metadata_string_replace",
    "metadata_string_replace_execute",
    "metadata_string_replace_params",
]
