from pathlib import Path
from typing import Any, Final

from lang_main.config import (
    BASE_FOLDERNAME,
    CONFIG_FILENAME,
    CYTO_STYLESHEET_FILENAME,
    PKG_DIR,
    STOP_FOLDER,
    get_config_paths,
    load_cfg,
)
from lang_main.search import search_base_path

# ** lang-main config
cfg_path_internal, cyto_stylesheet_path = get_config_paths(
    PKG_DIR, CONFIG_FILENAME, CYTO_STYLESHEET_FILENAME
)


CONFIG: Final[dict[str, Any]] = load_cfg(
    starting_path=PKG_DIR,
    glob_pattern=CONFIG_FILENAME,
    stop_folder_name=STOP_FOLDER,
)

lib_path = search_base_path(PKG_DIR, stop_folder_name=STOP_FOLDER)
if lib_path is None:
    raise FileNotFoundError('Could not resolve library path of application')
LIB_PATH: Final[Path] = lib_path
print(f'Library path is: {LIB_PATH}', flush=True)

root_path = search_base_path(PKG_DIR, stop_folder_name=BASE_FOLDERNAME)
if root_path is None:
    raise FileNotFoundError('Could not resolve root path of application')
ROOT_PATH: Final[Path] = root_path
print(f'Root path is: {ROOT_PATH}', flush=True)


# ** Cytoscape configuration
# stylesheet
if not cyto_stylesheet_path.exists():
    raise FileNotFoundError(
        f'Visual stylesheet for Cytoscape not found under: >>{cyto_stylesheet_path}<<'
    )

CYTO_PATH_STYLESHEET: Final[Path] = cyto_stylesheet_path
