"""
HA! I'm havin' a fok'n laugh m8!
Java is like "Write once, run anywhere"... OH WAIT! I actually do not accept any new path formats made after 1995
on Windows for starting a JAR application. Just put an asterisk next to the "run" word to be accurate.
Read the docstring of java_compatible_absolute_path() in the Windows implementation for details.
"""
import sys
from pathlib import Path
from typing import Union

from clarabot_nano.utility.path.validate import denormalize_absolute_path

if sys.platform.startswith("win"):

    def java_compatible_absolute_path(path: Union[Path, str]) -> str:
        r"""
        The preferred absolute paths we use on Windows are not supported well by the java launcher environment. No
        UNC or extended paths work for starting JAR applications actually. There is an ancient issue about it, but
        nobody cares: https://bugs.openjdk.java.net/browse/JDK-8058423
        It only mentions the \\HOSTNAME\SHARE\ (new-style) UNC, but the same error happens for \\?\ (extended) or
        \\?\UNC\HOSTNAME\SHARE\ paths as well. OpenJDK 11.0.10 btw.
        As a workaround we revert the path to old drive prefixed (DOS-style).
        NOTE: Even if Java supported the better formats, launching an application from a long-path does not work
        on Windows unless the long-path support is truly enabled. So the benefits of launching it from an UNC path
        does not really exist, aside from not requiring the additional path-wrangling here.
        """
        return denormalize_absolute_path(path)


else:

    def java_compatible_absolute_path(path: Union[Path, str]) -> str:
        """
        No other platform needs path-wrangling here afaik.
        """
        return str(path)
