/*
 * AUTH_HOLD.pgc - au 모듈 서비스 AUTH_HOLD (one service = one file).
 * 승인 보류: 승인/예비(A,P) 상태만 보류(H)로 전이, 반영 건수를 T_RC 로.
 * Rewritten with an inline UPDATE ... WHERE status IN (...) guard + affected-count
 * (via sqlca.sqlerrd[2]) so it is structurally DISTINCT from AUTH_APPROVE (dbio
 * wrapper) and AUTH_RELEASE (SELECT-then-UPDATE). Runs on the caller's XA branch.
 */
#include "AUTH_HOLD.h"

void AUTH_HOLD(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_auth, h_aff;
    EXEC SQL END DECLARE SECTION;

    h_auth = getl(b, T_ID1);
    /* only an approved(A)/pre-authorized(P) authorization may be put on hold */
    EXEC SQL UPDATE au_authorization SET status = 'H', updated_at = now()
        WHERE auth_id = :h_auth AND status IN ('A', 'P');
    if (sqlca.sqlcode < 0) { userlog("AUTH_HOLD FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); FAIL(b); }
    h_aff = sqlca.sqlerrd[2];
    if (h_aff > 0) Bchg(b, T_STATUS, 0, "H", 0L);
    setl(b, T_RC, h_aff > 0 ? 0 : 1);
    OK(b);
}
