from typing import Optional


def _reformat_args(
    args: list,
    inputs: Optional[dict] = None,
    expected: Optional[dict] = None,
    **kwargs
):
    """
    This is to support backward-compatibility for workflows using the old
    `run_workflow` signature in which the second argument was the workflow
    name. This will be removed in the next major version.

    Args:
        args: Positional arguments
        inputs: Inputs dict
        expected: Expected dict
        **kwargs: Additional keyword arguments

    Returns:
        Tuple of (inputs, expected, kwargs)
    """
    if args:
        if isinstance(args[0], str):
            kwargs["workflow_name"] = args.pop(0)
        if args:
            if inputs:
                raise TypeError("Multiple values for argument 'inputs'")
            inputs = args.pop(0)
            if args:
                if expected:
                    raise TypeError("Multiple values for argument 'expected'")
                expected = args.pop(0)
                if args:
                    raise TypeError("Too many arguments")

    return inputs, expected, kwargs