import os

def detectar_packs_halycon(omsi_root):
    addons_path = os.path.join(omsi_root, "Addons")
    packs = {}

    if not os.path.isdir(addons_path):
        return packs

    for item in os.listdir(addons_path):
        if not item.lower().startswith("halycon_ai_pack"):
            continue

        pack_path = os.path.join(addons_path, item)
        if not os.path.isdir(pack_path):
            continue

        pack_data = {
            "path": pack_path,
            "humans": {},
            "drivers": {}
        }

        humans_root = os.path.join(pack_path, "Humans_Konfigurationen")
        if os.path.isdir(humans_root):
            for cfg in os.listdir(humans_root):
                p = os.path.join(humans_root, cfg, "humans.txt")
                if os.path.isfile(p):
                    pack_data["humans"][cfg] = p

        drivers_root = os.path.join(pack_path, "Busfahrer_Konfigurationen")
        if os.path.isdir(drivers_root):
            for cfg in os.listdir(drivers_root):
                p = os.path.join(drivers_root, cfg, "drivers.txt")
                if os.path.isfile(p):
                    pack_data["drivers"][cfg] = p

        packs[item] = pack_data

    return packs


def detectar_mapas(omsi_root):
    maps_path = os.path.join(omsi_root, "maps")
    if not os.path.isdir(maps_path):
        return []

    return sorted(
        d for d in os.listdir(maps_path)
        if os.path.isdir(os.path.join(maps_path, d))
    )
