/*
 * mm_status_dbio.pgc - 가맹점 상태 조회 (libmmdbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_status_dbio.h"

int mmdb_merch_status(const char *merch, char *status_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_status[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    /* 확장 마스터 등급/상태를 함께 보고 유효 상태를 CASE 로 도출한다. */
    EXEC SQL SELECT CASE WHEN status = 'ACTIVE' AND grade IN ('S','A','B','C')
                         THEN status ELSE 'HOLD' END
        INTO :h_status FROM mm_merchant_ext WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("mmdb_merch_status FAIL [%d]", sqlca.sqlcode); return -1; }
    strncpy(status_out, h_status, 15); status_out[15] = 0;
    return 0;
}
