import logging
import sys
from typing import List

logger = logging.getLogger(__name__)


if sys.platform.startswith("win"):
    import win32api
    from clarabot_nano.utility.path.nt import list_network_shortcut_paths, read_shortcut_target_path

    def get_root_paths() -> List[str]:
        """
        Drives are an easy given to be discovered and used. Network locations not so much, unless they are
        mounted as a drive with "net use" or similar. The problem is that the network locations do not appear
        as real mount on Windows, but they are folders with metadata files inside them like "target.lnk".
        We try to discover them and extract the target location for use. This may be impossible as a link may
        have a target that cannot be represented with a path, not even with UNC. For example: "ftp://xy"
        """
        roots = win32api.GetLogicalDriveStrings().replace("\\", "/").split("\x00")[:-1]
        try:
            network_roots = read_shortcut_target_path(list_network_shortcut_paths())
        except Exception:
            logger.exception("Failed to list locations from network shortcuts.")
        else:
            for network_root in network_roots:
                roots.append(network_root.replace("\\", "/"))
        return roots


elif sys.platform.startswith("linux"):

    def get_root_paths() -> List[str]:
        return ["/", "/home"]


elif sys.platform.startswith("darwin"):

    def get_root_paths() -> List[str]:
        return ["/", "/Users", "/Volumes"]


else:
    raise NotImplementedError()
