"""
04단계: GT 프로필 + 전구간 EV 필터 매칭 파이프라인.
"""

from __future__ import annotations

from pathlib import Path

from deepcoin.matching.pipeline import run_matching_pipeline
from deepcoin.paths import ANALYSIS_TRADES_CSV, REPORTS_ANALYSIS, REPORTS_MATCHING


def run_match(
    phase: str = "all",
    trades_csv: Path | None = None,
) -> None:
    """
    04 파이프라인 실행.

    Args:
        phase: all | profile | scan | label | select.
        trades_csv: 03b CSV 경로(선택).
    """
    REPORTS_MATCHING.mkdir(parents=True, exist_ok=True)
    csv = trades_csv or ANALYSIS_TRADES_CSV
    if not csv.is_file():
        raise FileNotFoundError(
            f"03b CSV 없음: {csv}\n  python scripts/03_analyze_trades.py 먼저 실행"
        )
    run_matching_pipeline(phase=phase, trades_csv=csv)


def run_match_stub() -> Path:
    """하위 호환: 스텁 대신 phase=profile만 안내."""
    print("=== Phase 04 Matching ===")
    print("  전체 파이프라인: python scripts/04_match_rules.py")
    print("  단계별: --phase profile|scan|label|select")
    print(f"  analysis csv: {ANALYSIS_TRADES_CSV}")
    print(f"  output dir:   {REPORTS_MATCHING}")
    return REPORTS_MATCHING


if __name__ == "__main__":
    run_match()
