"""스레드를 배치로 분할하여 개별 JSON 파일로 저장."""
from __future__ import annotations

import json
import math
from pathlib import Path

BATCH_SIZE = 80  # 배치당 스레드 수

def main() -> None:
    threads = json.loads(Path("/tmp/threads.json").read_text(encoding="utf-8"))
    total = len(threads)
    num_batches = math.ceil(total / BATCH_SIZE)

    output_dir = Path("/tmp/thread_batches")
    output_dir.mkdir(exist_ok=True)

    for i in range(num_batches):
        start = i * BATCH_SIZE
        end = min(start + BATCH_SIZE, total)
        batch = threads[start:end]

        output_path = output_dir / f"batch_{i:02d}.json"
        output_path.write_text(
            json.dumps(batch, ensure_ascii=False, indent=2),
            encoding="utf-8",
        )
        print(f"배치 {i}: 스레드 {start}~{end-1} ({len(batch)}개) → {output_path}")

    print(f"\n총 {num_batches}개 배치 생성 완료")


if __name__ == "__main__":
    main()
