/*
 * MM_HOLIDAY_REG.pgc - mm 모듈 서비스 MM_HOLIDAY_REG (one service = one file).
 * 기능: 공휴일 마스터 등록.
 * 기존 인라인 mm_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * mm_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "MM_HOLIDAY_REG.h"

void MM_HOLIDAY_REG(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char hdate[16], name[64];
    EXEC SQL BEGIN DECLARE SECTION;
    char h_date[16], h_name[64];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_BIZDATE, hdate, sizeof(hdate));
    if (hdate[0] == 0) { userlog("MM_HOLIDAY_REG: T_BIZDATE 누락"); FAIL(b); }
    gets_(b, T_STR1, name, sizeof(name)); if (name[0] == 0) strcpy(name, "공휴일");
    strncpy(h_date, hdate, sizeof(h_date)-1); h_date[sizeof(h_date)-1] = 0;
    strncpy(h_name, name,  sizeof(h_name)-1); h_name[sizeof(h_name)-1] = 0;
    EXEC SQL INSERT INTO mm_holiday (holiday_date, holiday_name)
        VALUES (:h_date, :h_name)
        ON CONFLICT (holiday_date) DO UPDATE SET holiday_name = EXCLUDED.holiday_name;
    if (sqlca.sqlcode < 0) { userlog("MM_HOLIDAY_REG FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); FAIL(b); }
    OK(b);
}
