#!/bin/bash
## Run the acquiring drivers under real global XA transactions.
##   ./run-driver.sh            -> demo: COMMIT chain, ROLLBACK chain, ops, batches
##   ./run-driver.sh <merch> <amount> <bizdate> [abort]  -> single custom chain run
. /app/conf/setapp.sh

if [ "$#" -ge 1 ]; then
    exec /app/bin/acqdrv "$@"
fi

echo "===== 1) 매입 체인 COMMIT (ACQUIRE -> RECONCILE -> SETTLE, tpcommit) ====="
/app/bin/acqdrv M0001 1000000 2026-07-19

echo
echo "===== 2) 매입 체인 ROLLBACK (동일 체인, tpabort) ====="
/app/bin/acqdrv M0002 500000 2026-07-19 abort

echo
echo "===== 3) ac 온라인 서비스 ops (DUPCHK/FEEADJ/INSTALL/STATUS, tpcommit) ====="
LASTPID=$(PGPASSWORD=acq psql -h db -U acq -d acq -tAc "SELECT max(purchase_id) FROM purchase")
/app/bin/ac_ops "${LASTPID:-1}" M0001 1000000 2026-07-19

echo
echo "===== 4) ac 배치: 가맹점 일집계 (커서 + XA) ====="
/app/bin/ac_merchsum_batch 2026-07-19

echo
echo "===== 5) ac 배치: 원천징수 (커서 + XA) ====="
/app/bin/ac_wht_batch 2026-07-19
