"""업종·템플릿 정의. 프론트와 같은 파일(solution/shared/src/data/templates.json)을 읽는다.""" import json from pathlib import Path from common.enums import PlaceCategory CATALOG_PATH = Path(__file__).resolve().parents[2] / "shared" / "src" / "data" / "templates.json" _CATALOG = json.loads(CATALOG_PATH.read_text(encoding="utf-8")) TEMPLATES: dict = _CATALOG["templates"] INDUSTRIES: dict = _CATALOG["industries"] _INDUSTRY_BY_CATEGORY = { PlaceCategory.LODGING.value: "stay", PlaceCategory.CAFE.value: "cafe", PlaceCategory.RESTAURANT.value: "restaurant", PlaceCategory.CLINIC.value: "clinic", } class UnknownTemplate(ValueError): pass def industry_of(category: int) -> dict: key = _INDUSTRY_BY_CATEGORY.get(category) if key is None: raise ValueError(f"업종 코드에 맞는 정의가 없다: {category}") return INDUSTRIES[key] def is_allowed(category: int, template_id: str) -> bool: return template_id in industry_of(category)["templates"] def resolve_template_id(category: int, stored: str | None) -> str: template_id = (stored or "").strip() or industry_of(category)["defaultTemplate"] if not is_allowed(category, template_id): raise UnknownTemplate(f"업종 {category}에서 쓸 수 없는 템플릿: {template_id}") return template_id