from pathlib import Path
from typing import Dict
from typing import Any
from typing import List


def get_account_info(path: Path) -> Dict[str, Any]:
    """Parse wow folder for accounts, servers and characters."""

    def _parse_wow_path(path: Any) -> List[str]:
        excluded_folders = [".DS_Store", "SavedVariables"]
        path_ends = [child.parts[-1] for child in path.iterdir()]
        path_ends_clean = [
            pe for pe in path_ends if pe not in excluded_folders and "." not in pe
        ]
        return path_ends_clean

    acc_path = path.joinpath("WTF").joinpath("Account")
    resources: Dict[str, Any] = {}

    for account in _parse_wow_path(acc_path):
        account_path = Path(acc_path).joinpath(account)
        resources[account] = {"servers": {}}

        for server in _parse_wow_path(account_path):
            server_path = Path(account_path).joinpath(server)
            resources[account]["servers"][server] = {"characters": []}

            for char in _parse_wow_path(server_path):
                resources[account]["servers"][server]["characters"].append(char)
    return resources