#!/usr/bin/env python3
"""Create reconciliation candidates from local external records.

This script is safe to run from cron/systemd timer. It is idempotent and only
creates/updates reconciliation_items for information already known locally, such
as Jasmin commercial documents without opportunity_id.
"""
from __future__ import annotations

from app.db import init_db
from app.reconciliation_service import sync_local_documents_without_opportunity


def main() -> None:
    init_db()
    result = sync_local_documents_without_opportunity(limit=500)
    print(
        "Reconciliation sync finished: "
        f"seen={result.get('seen', 0)} "
        f"created_or_updated={result.get('created_or_updated', 0)}"
    )


if __name__ == "__main__":
    main()
