#!/usr/bin/env python3
"""CLI: Run pipeline in dry-run mode (no real CRM writes)."""

import argparse
import sys

from agent_samochodowy.config import Settings
from agent_samochodowy.dgred.client import DgredClient
from agent_samochodowy.ingestor.csv_source import CsvSource
from agent_samochodowy.logging_config import setup_logging
from agent_samochodowy.matcher.index import CatalogIndex
from agent_samochodowy.orchestrator import Pipeline


def main() -> int:
    parser = argparse.ArgumentParser(description="Dry-run the pipeline (no CRM writes)")
    parser.add_argument("--source", default="data/samples/posts.json", help="Posts file")
    args = parser.parse_args()

    settings = Settings()
    settings.dry_run = True  # Always dry-run

    setup_logging(settings.log_level)

    source = CsvSource(args.source)
    index = CatalogIndex(settings.db_path)
    dgred = DgredClient(settings)

    try:
        pipeline = Pipeline(settings, source, index, dgred)
        stats = pipeline.run()
        print(f"\n{stats.summary()}")
        return 0
    finally:
        index.close()
        dgred.close()


if __name__ == "__main__":
    sys.exit(main())
