/*
 * mm_rate_minmax_dbio.pgc - mm 모듈 DB 접근 함수 (mm_rate_minmax_dbio), archived into libmmdbio.a.
 * 카드유형 수수료율 최소/최대 (min/max).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_rate_minmax_dbio.h"

/* card_type 수수료율의 최소/최대 bps 를 반환. */
int mmdb_rate_minmax(const char *card_type, long *lo, long *hi)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_ct[16];
    long h_lo = 0, h_hi = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_ct, card_type, sizeof(h_ct)-1); h_ct[sizeof(h_ct)-1] = 0;
    EXEC SQL SELECT coalesce(min(rate_bps),0), coalesce(max(rate_bps),0)
        INTO :h_lo, :h_hi FROM mm_fee_rate WHERE card_type = :h_ct;
    if (sqlca.sqlcode < 0) return -1;
    *lo = h_lo; *hi = h_hi;
    return 0;
}
