"""
模块入口：

  python -m moduleatlas

默认读取当前目录的 project_map.json，并输出：
- architecture.json
- architecture.md

你也可以通过命令行参数指定输入/输出路径。
"""

from __future__ import annotations

import argparse

from .runner import ModuleAtlasConfig, run_moduleatlas


def _parse_args() -> ModuleAtlasConfig:
    p = argparse.ArgumentParser(prog="moduleatlas", add_help=True)
    p.add_argument("--project-map", default="project_map.json", help="Path to project_map.json from FileAtlas")
    p.add_argument("--out-json", default="architecture.json", help="Output path for architecture.json")
    p.add_argument("--out-md", default="architecture.md", help="Output path for architecture.md")
    p.add_argument("--llm-concurrency", type=int, default=4, help="Concurrent module summaries (best-effort)")
    p.add_argument(
        "--max-evidence-per-edge",
        type=int,
        default=20,
        help="Cap evidence items per aggregated module edge (limits architecture.json size)",
    )
    p.add_argument(
        "--split-large-module-threshold",
        type=int,
        default=200,
        help="Split modules with file_count >= threshold into 2nd-level submodules (0 disables)",
    )
    args = p.parse_args()
    return ModuleAtlasConfig(
        project_map_path=str(args.project_map),
        out_json_path=str(args.out_json),
        out_md_path=str(args.out_md),
        llm_concurrency=int(args.llm_concurrency),
        max_evidence_per_edge=int(args.max_evidence_per_edge),
        split_large_module_file_count_threshold=int(args.split_large_module_threshold),
    )


def main() -> int:
    run_moduleatlas(_parse_args())
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

