import subprocess
import sys


def platform_fix_spawn_child_kwargs(kwargs: dict, gui_type=False) -> dict:
    """
    Platform specific configurations to support signaling the children processes.
    On Windows the child processes must be of GUI type to have sufficient signaling.
    """
    if sys.platform.startswith("win"):
        if not gui_type:
            if (creationflags := kwargs.get("creationflags")) is None:
                creationflags = 0
            creationflags |= subprocess.CREATE_NEW_CONSOLE
            kwargs["creationflags"] = creationflags
            # Hide the console/window of a child processes that is not a gui type service.
            if (startupinfo := kwargs.get("startupinfo")) is None:
                startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow |= subprocess.SW_HIDE  # this is for show because the hide constant is actually 0
            kwargs["startupinfo"] = startupinfo
    return kwargs
