# src/config/deployment.py
"""배포 역할: 코드 한 벌, 환경/프로세스 두 벌(server vs local)."""
import os

# server: 원격 DATABASE_URL 기준 전체 API + 배치/Celery
# local:  챗봇·헬스 등 최소 블루프린트만 (DB 의존 API는 프론트가 서버 URL로 호출)
MLINK_APP_ROLE = os.getenv("MLINK_APP_ROLE", "server").strip().lower()

# Flask Blueprint.name 과 일치 (routes/common.py → 'common' 등)
LOCAL_DEV_BLUEPRINT_NAMES = frozenset({"common", "chatbot", "chatbot2"})


def is_server_role() -> bool:
    return MLINK_APP_ROLE != "local"


def is_local_role() -> bool:
    return MLINK_APP_ROLE == "local"


def filter_blueprints(blueprint_pairs: list) -> list:
    """(blueprint, url_prefix) 목록을 역할에 따라 축소."""
    if is_server_role():
        return blueprint_pairs
    out = []
    for bp, prefix in blueprint_pairs:
        if bp.name in LOCAL_DEV_BLUEPRINT_NAMES:
            out.append((bp, prefix))
    return out
