"""Archive only the actual export after exact structure/date/arithmetic validation."""
import argparse,json
from generated.verify_ledger_json import ProductionLedgerJsonAuditor
from generated.archive_tax_reports import archive_report,load_password
from infinbot_common import private_read,strict_json,Rejected


if __name__=='__main__':
    p=argparse.ArgumentParser();p.add_argument('--config',required=True);args=p.parse_args()
    try:
        c=strict_json(private_read(args.config))
        if ProductionLedgerJsonAuditor(c['export_path']).validate()['status']!='PASS':raise Rejected('Current export audit blocked')
        print(json.dumps(archive_report(c['export_path'],c['backup_dir'],load_password(c['archive_password_file'],True)),indent=2))
    except Exception:print(json.dumps({'status':'ARCHIVE_BLOCKED','source_deleted':False}));raise SystemExit(1)
