/*
 * au_fraud_casescore_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_fraud_casescore_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: CASE WHEN 으로 점수 구간별 가중치를 합산하여 위험 점수 총합 반환.
 */
#include <string.h>
#include <userlog.h>
#include "au_fraud_casescore_dbio.h"

/* score 구간에 3/2/1 가중치를 부여한 CASE 합계(위험 가중 점수)를 반환. */
long audb_fraud_high_weight(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(sum(
        CASE WHEN score >= 80 THEN 3
             WHEN score >= 50 THEN 2
             ELSE 1 END), 0)
        INTO :h_v FROM au_fraud_log WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
