"""ai-image-gen 공통 설정 모듈.

모든 gen_*.py, rerender_*.py 파일이 이 모듈을 통해 경로 및 디자인 토큰에 접근.
Usage:
    from gen_config import WORKSPACE_ROOT, FONT_DIR, HEADLINE_MIN_PX, ...
"""

import sys
from pathlib import Path

# workspace root 참조를 위한 path 설정
_WORKSPACE_ROOT = Path(__file__).resolve().parent.parent.parent
if str(_WORKSPACE_ROOT) not in sys.path:
    sys.path.insert(0, str(_WORKSPACE_ROOT))

from config.loader import ConfigManager  # noqa: E402
from tools.dq_rules import ABSOLUTE_MIN_PX, DQ_RULES  # noqa: E402

_cfg = ConfigManager.get_instance()

# ── 경로 ──
WORKSPACE_ROOT = Path(_cfg.get_path("roots.workspace"))
FONT_DIR = Path.home() / ".local/share/fonts" / "Pretendard"

# ── DQ 폰트 사이즈 (최소값) ──
CORE_METRIC_MIN_PX = DQ_RULES["font_sizes"]["core_metric"]["min"]  # 96
HEADLINE_MIN_PX = DQ_RULES["font_sizes"]["headline"]["min"]  # 84
SUBHEAD_MIN_PX = DQ_RULES["font_sizes"]["subhead"]["min"]  # 64
CTA_MIN_PX = DQ_RULES["font_sizes"]["cta"]["min"]  # 40
DISCLAIMER_MIN_PX = DQ_RULES["font_sizes"]["disclaimer"]["min"]  # 40

# ── DQ 폰트 비율 ──
HEAD_SUB_RATIO = DQ_RULES["font_ratio"]["min_head_sub_ratio"]  # 1.3


# ── 공용 @font-face CSS 블록 ──
def get_font_face_css() -> str:
    """Pretendard @font-face CSS 블록 반환 (f-string 내 삽입용)."""
    return f"""  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{FONT_DIR}/Pretendard-Black.otf') format('opentype');
    font-weight: 900;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{FONT_DIR}/Pretendard-ExtraBold.otf') format('opentype');
    font-weight: 800;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{FONT_DIR}/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{FONT_DIR}/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{FONT_DIR}/Pretendard-Regular.otf') format('opentype');
    font-weight: 400;
  }}"""
