/*
 * AUTH_RETRY.pgc - au 모듈 서비스 AUTH_RETRY (one service = one file).
 * 거절 승인 재시도 (상태 D->A 재승인).
 * Moved verbatim from the former inline au_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by au_svr at tpsvrinit.
 */
#include "AUTH_RETRY.h"

void AUTH_RETRY(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24];
    long auth_id = getl(b, T_ID1), amount = getl(b, T_AMOUNT), lim = 0, used = 0;
    gets_(b, T_KEY1, card, sizeof(card));
    if (audb_limit_get(card, &lim, &used) < 0) FAIL(b);
    if (used + amount > lim) { setl(b, T_RC, 1); FAIL(b); }
    if (audb_update_auth_status(auth_id, "A") < 0) FAIL(b);
    if (audb_limit_dec(card, amount) < 0) FAIL(b);
    setl(b, T_RC, 0);
    Bchg(b, T_STATUS, 0, "A", 0L);
    OK(b);
}
