/*
 * VL_MERCH.pgc - vl 모듈 서비스 VL_MERCH (one service = one file).
 * 기능: 가맹점 상태 검증 (merchant.status != ACTIVE → RC 1).
 * 기존 인라인 vl_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * vl_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "VL_MERCH.h"

void VL_MERCH(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64];
    long rc = 0;
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_status[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    EXEC SQL SELECT status INTO :h_status FROM merchant WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { setl(b, T_RC, 2); OK(b); }
    if (strcmp(h_status, "ACTIVE") != 0) rc = 1;
    Bchg(b, T_STATUS, 0, h_status, 0L);
    setl(b, T_RC, rc);
    OK(b);
}
