# config/loader.py
import os
import json
from typing import Dict, Any, List

CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")

def load_config(file_path: str = CONFIG_PATH) -> Dict[str, Any]:
    if not os.path.exists(file_path):
        raise FileNotFoundError(f"Configuration file not found: {file_path}")
    
    with open(file_path, "r", encoding="utf-8") as f:
        return json.load(f)

CONFIG = load_config()

def get_active_crawler_config(cfg: Dict[str, Any] = None) -> Dict[str, Any]:
    if cfg is None:
        cfg = load_config()

    is_dev = cfg.get("develop_mode", False)
    crawler_cfg = dict(cfg.get("crawler", {}))

    if is_dev:
        dev_cfg = cfg.get("develop_configs", {})
        crawler_cfg.update(dev_cfg)

    return crawler_cfg

def get_active_hashtags(cfg: Dict[str, Any] = None) -> List[str]:
    if cfg is None:
        cfg = load_config()

    all_tags = cfg.get("hashtags", [])
    if cfg.get("develop_mode", False):
        dev_cfg = cfg.get("develop_configs", {})
        limit = dev_cfg.get("tags_count", 5)
        return all_tags[:limit]
    
    return all_tags