# recharge/services/plan_cache.py
from django.conf import settings
from pathlib import Path
import json

def load_cached_plans(provider_key: str, operator_code: str, circle_code: str) -> dict | None:
    cache_root = Path(getattr(settings, "PLANS_CACHE_DIR", Path("."))) / provider_key
    fpath = cache_root / f"{operator_code}_{circle_code}.json"
    if not fpath.exists():
        return None
    with open(fpath, "r", encoding="utf-8") as f:
        return json.load(f)
