"""
Corpus Saver
============
Save processed corpus to disk as JSON files
"""

import json
from pathlib import Path
from typing import Dict, List

class CorpusSaver:
    def __init__(self, output_dir: str = "processed_corpus"):
        self.output_dir = Path(output_dir)
        self.output_dir.mkdir(exist_ok=True)

    def save(self, processed_corpus: Dict[str, List[dict]]) -> str:
        """
        Save the processed corpus as JSON per category.
        Returns path to the main output directory.
        """
        for category, docs in processed_corpus.items():
            file_path = self.output_dir / f"{category}.json"
            with file_path.open("w", encoding="utf-8") as f:
                json.dump(docs, f, ensure_ascii=False, indent=2)
        return str(self.output_dir)
