/*
 * cl_dbio.h - cl 모듈 (마감/closing) DB 접근 계층 (libcldbio.a).
 * ECPG (EXEC SQL) functions compiled into a static library and linked into
 * cl_svr and the cl batches. They run on the caller's XA branch/connection
 * (no EXEC SQL CONNECT); sqlca is the shared per-thread ECPG SQLCA.
 * Return convention: 0 = ok, -1 = SQL error (caller may also inspect sqlca).
 */
#ifndef CL_DBIO_H
#define CL_DBIO_H

/* 마감 이력 (close_log) */
long cldb_next_close_id(void);
int  cldb_insert_close(long cid, const char *ctype, const char *period,
                       const char *bizdate, const char *status,
                       long txn_count, long total_amount, const char *memo);
int  cldb_update_close_status(long cid, const char *status);
int  cldb_get_close_status(long cid, char *out /* >= 2 bytes */);
int  cldb_update_close_totals(long cid, long txn_count, long total_amount);

/* 마감 스냅샷 (snapshot) */
long cldb_next_snapshot_id(void);
int  cldb_insert_snapshot(long sid, long cid, const char *period, const char *bizdate,
                          const char *merch, long gross, long fee, long net, long cnt);

/* 마감 순번 관리 (seq registry) */
long cldb_bump_seq(const char *ctype);

/* 일/월/분기/연 공용: 매입 집계(count/sum) 후 마감이력(status=C) 생성.
 * cnt_out/amt_out 로 집계값 반환. DAILY 는 당일, 그 외는 period 프리픽스 집계. */
int  cldb_open_close(const char *ctype, const char *period, const char *bizdate,
                     long *cid_out, long *cnt_out, long *amt_out);

#endif /* CL_DBIO_H */
