/*
 * st_svr.pgc - st (정산/수수료) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of st's 133 online services now lives in its own file
 * (app/src/st/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/st/svc/<SVCNAME>.h); those objects are archived into libstsvc.a and
 * linked into this server. Here we only include every service copybook, tpopen()
 * the ECPG XA RM, tpadvertise() all services from a {name, fn} table, and
 * tpclose() at shutdown.
 *
 * st_svr: ONE binary that tpadvertise()s ALL 133 online st(정산/수수료) services.
 * SETTLE keeps the proven behavior: its own XA branch writes the settlement +
 * settle ledger rows. Terminal service of the 매입 chain.
 */
#include <atmi.h>
#include <ubf.h>
#include <userlog.h>

/* every st service's copybook header (declares its record struct + prototype) */
#include "SETTLE.h"
#include "ST_MDR.h"
#include "ST_NETTING.h"
#include "ST_VAT.h"
#include "ST_VANFEE.h"
#include "ST_RELAYFEE.h"
#include "ST_WHT.h"
#include "ST_ADJUST.h"
#include "ST_ADVANCE.h"
#include "ST_DELAYINT.h"
#include "ST_HOLD.h"
#include "ST_RELEASE.h"
#include "ST_SPLIT.h"
#include "ST_PAYDATE.h"
#include "ST_BYMERCH.h"
#include "ST_MONTHLY.h"
#include "ST_OFFSET.h"
#include "ST_DIFFCHK.h"
#include "ST_RECALC.h"
#include "ST_RATEAPPLY.h"
#include "ST_REPORT.h"
#include "ST_XFERLINK.h"
#include "ST_STATS.h"
#include "ST_CANCEL.h"
#include "ST_LEDGERLINK.h"
#include "ST_BANDRATE.h"
#include "ST_CAP.h"
#include "ST_FXCONV.h"
#include "ST_CONFIRM.h"
#include "ST_STATUS.h"
#include "ST_RATESIM.h"
#include "ST_PROMOCALC.h"
#include "ST_PARTIAL.h"
#include "ST_RERUN.h"
#include "ST_CXLRECALC.h"
#include "ST_RETRORATE.h"
#include "ST_TIERINCENT.h"
#include "ST_CYCLED1.h"
#include "ST_CYCLED2.h"
#include "ST_CYCLEWEEK.h"
#include "ST_CYCLEMON.h"
#include "ST_DEPOSITCUT.h"
#include "ST_RECVOFFSET.h"
#include "ST_DEBTCOLLECT.h"
#include "ST_VATREPORT.h"
#include "ST_WHTREPORT.h"
#include "ST_APPROVE.h"
#include "ST_GRPSETTLE.h"
#include "ST_DISPUTE.h"
#include "ST_STATDETAIL.h"
#include "ST_FEEPREVIEW.h"
#include "ST_HOLDAMT.h"
#include "ST_PAYSTATUS.h"
#include "ST_ADJHIST.h"
#include "ST_DTLSUM.h"
#include "ST_MERCHRATE.h"
#include "ST_CAPCHECK.h"
#include "ST_ROUNDING.h"
#include "ST_MINFEE.h"
#include "ST_DAILYCLOSE.h"
#include "ST_REOPEN.h"
#include "ST_CARRYOVER.h"
#include "ST_NEGSWEEP.h"
#include "ST_TOPMERCH.h"
#include "ST_FEERATIO.h"
#include "ST_SPLITEVEN.h"
#include "ST_CHNLSTAT.h"
#include "ST_ISSUERSTAT.h"
#include "ST_TAXINVCHK.h"
#include "ST_FXSETTLE.h"
#include "ST_EDIRECON.h"
#include "ST_UNPAIDSUM.h"
#include "ST_PAYRETRY.h"
#include "ST_LIMITCHK.h"
#include "ST_LEDGERSNAP.h"
#include "ST_FLATFEE.h"
#include "ST_PCTFEE.h"
#include "ST_SLABFEE.h"
#include "ST_BANDSIM.h"
#include "ST_RATECARD.h"
#include "ST_RATECMP.h"
#include "ST_TIERFEE.h"
#include "ST_FLATVSPCT.h"
#include "ST_RATEMAX.h"
#include "ST_RATEFLOOR.h"
#include "ST_PROMOAPPLY.h"
#include "ST_EVENTFEE.h"
#include "ST_PARTNERSET.h"
#include "ST_COUPONADJ.h"
#include "ST_CASHBACK.h"
#include "ST_MKTGSHARE.h"
#include "ST_CYCLED3.h"
#include "ST_INSTANTPAY.h"
#include "ST_BIWEEKLY.h"
#include "ST_CYCLEQTR.h"
#include "ST_CYCLESET.h"
#include "ST_NEXTPAYDT.h"
#include "ST_PARTPAY.h"
#include "ST_REPARTIAL.h"
#include "ST_VOIDRECALC.h"
#include "ST_REFUNDCALC.h"
#include "ST_CHARGEBACK.h"
#include "ST_ADJREVERSE.h"
#include "ST_REBATE.h"
#include "ST_VOLREBATE.h"
#include "ST_LOYALTY.h"
#include "ST_GROWTHINC.h"
#include "ST_REFERRAL.h"
#include "ST_DEPOSITSET.h"
#include "ST_RECVAGE.h"
#include "ST_BADDEBT.h"
#include "ST_DEBTNET.h"
#include "ST_COLLATERAL.h"
#include "ST_RECVSTAT.h"
#include "ST_VATDETAIL.h"
#include "ST_WHTDETAIL.h"
#include "ST_TAXSUMMARY.h"
#include "ST_SUPPLYCALC.h"
#include "ST_VATADJUST.h"
#include "ST_PRECONFIRM.h"
#include "ST_LOCKBATCH.h"
#include "ST_UNLOCK.h"
#include "ST_APPROVEALL.h"
#include "ST_WORKFLOW.h"
#include "ST_GRPROLLUP.h"
#include "ST_GRPALLOC.h"
#include "ST_CHAINSET.h"
#include "ST_DISPUTERSV.h"
#include "ST_APPEALSTAT.h"
#include "ST_VANDETAIL.h"
#include "ST_RELAYSPLIT.h"
#include "ST_GRADESTAT.h"
#include "ST_MONTHSTAT.h"

/* ----- advertise table: {service name, function} ---------------------- */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"SETTLE", SETTLE},  {"ST_MDR", ST_MDR},
    {"ST_NETTING", ST_NETTING},  {"ST_VAT", ST_VAT},
    {"ST_VANFEE", ST_VANFEE},  {"ST_RELAYFEE", ST_RELAYFEE},
    {"ST_WHT", ST_WHT},  {"ST_ADJUST", ST_ADJUST},
    {"ST_ADVANCE", ST_ADVANCE},  {"ST_DELAYINT", ST_DELAYINT},
    {"ST_HOLD", ST_HOLD},  {"ST_RELEASE", ST_RELEASE},
    {"ST_SPLIT", ST_SPLIT},  {"ST_PAYDATE", ST_PAYDATE},
    {"ST_BYMERCH", ST_BYMERCH},  {"ST_MONTHLY", ST_MONTHLY},
    {"ST_OFFSET", ST_OFFSET},  {"ST_DIFFCHK", ST_DIFFCHK},
    {"ST_RECALC", ST_RECALC},  {"ST_RATEAPPLY", ST_RATEAPPLY},
    {"ST_REPORT", ST_REPORT},  {"ST_XFERLINK", ST_XFERLINK},
    {"ST_STATS", ST_STATS},  {"ST_CANCEL", ST_CANCEL},
    {"ST_LEDGERLINK", ST_LEDGERLINK},  {"ST_BANDRATE", ST_BANDRATE},
    {"ST_CAP", ST_CAP},  {"ST_FXCONV", ST_FXCONV},
    {"ST_CONFIRM", ST_CONFIRM},  {"ST_STATUS", ST_STATUS},
    {"ST_RATESIM", ST_RATESIM},  {"ST_PROMOCALC", ST_PROMOCALC},
    {"ST_PARTIAL", ST_PARTIAL},  {"ST_RERUN", ST_RERUN},
    {"ST_CXLRECALC", ST_CXLRECALC},  {"ST_RETRORATE", ST_RETRORATE},
    {"ST_TIERINCENT", ST_TIERINCENT},  {"ST_CYCLED1", ST_CYCLED1},
    {"ST_CYCLED2", ST_CYCLED2},  {"ST_CYCLEWEEK", ST_CYCLEWEEK},
    {"ST_CYCLEMON", ST_CYCLEMON},  {"ST_DEPOSITCUT", ST_DEPOSITCUT},
    {"ST_RECVOFFSET", ST_RECVOFFSET},  {"ST_DEBTCOLLECT", ST_DEBTCOLLECT},
    {"ST_VATREPORT", ST_VATREPORT},  {"ST_WHTREPORT", ST_WHTREPORT},
    {"ST_APPROVE", ST_APPROVE},  {"ST_GRPSETTLE", ST_GRPSETTLE},
    {"ST_DISPUTE", ST_DISPUTE},  {"ST_STATDETAIL", ST_STATDETAIL},
    {"ST_FEEPREVIEW", ST_FEEPREVIEW},  {"ST_HOLDAMT", ST_HOLDAMT},
    {"ST_PAYSTATUS", ST_PAYSTATUS},  {"ST_ADJHIST", ST_ADJHIST},
    {"ST_DTLSUM", ST_DTLSUM},  {"ST_MERCHRATE", ST_MERCHRATE},
    {"ST_CAPCHECK", ST_CAPCHECK},  {"ST_ROUNDING", ST_ROUNDING},
    {"ST_MINFEE", ST_MINFEE},  {"ST_DAILYCLOSE", ST_DAILYCLOSE},
    {"ST_REOPEN", ST_REOPEN},  {"ST_CARRYOVER", ST_CARRYOVER},
    {"ST_NEGSWEEP", ST_NEGSWEEP},  {"ST_TOPMERCH", ST_TOPMERCH},
    {"ST_FEERATIO", ST_FEERATIO},  {"ST_SPLITEVEN", ST_SPLITEVEN},
    {"ST_CHNLSTAT", ST_CHNLSTAT},  {"ST_ISSUERSTAT", ST_ISSUERSTAT},
    {"ST_TAXINVCHK", ST_TAXINVCHK},  {"ST_FXSETTLE", ST_FXSETTLE},
    {"ST_EDIRECON", ST_EDIRECON},  {"ST_UNPAIDSUM", ST_UNPAIDSUM},
    {"ST_PAYRETRY", ST_PAYRETRY},  {"ST_LIMITCHK", ST_LIMITCHK},
    {"ST_LEDGERSNAP", ST_LEDGERSNAP},
    {"ST_FLATFEE", ST_FLATFEE},     {"ST_PCTFEE", ST_PCTFEE},
    {"ST_SLABFEE", ST_SLABFEE},     {"ST_BANDSIM", ST_BANDSIM},
    {"ST_RATECARD", ST_RATECARD},     {"ST_RATECMP", ST_RATECMP},
    {"ST_TIERFEE", ST_TIERFEE},     {"ST_FLATVSPCT", ST_FLATVSPCT},
    {"ST_RATEMAX", ST_RATEMAX},     {"ST_RATEFLOOR", ST_RATEFLOOR},
    {"ST_PROMOAPPLY", ST_PROMOAPPLY},     {"ST_EVENTFEE", ST_EVENTFEE},
    {"ST_PARTNERSET", ST_PARTNERSET},     {"ST_COUPONADJ", ST_COUPONADJ},
    {"ST_CASHBACK", ST_CASHBACK},     {"ST_MKTGSHARE", ST_MKTGSHARE},
    {"ST_CYCLED3", ST_CYCLED3},     {"ST_INSTANTPAY", ST_INSTANTPAY},
    {"ST_BIWEEKLY", ST_BIWEEKLY},     {"ST_CYCLEQTR", ST_CYCLEQTR},
    {"ST_CYCLESET", ST_CYCLESET},     {"ST_NEXTPAYDT", ST_NEXTPAYDT},
    {"ST_PARTPAY", ST_PARTPAY},     {"ST_REPARTIAL", ST_REPARTIAL},
    {"ST_VOIDRECALC", ST_VOIDRECALC},     {"ST_REFUNDCALC", ST_REFUNDCALC},
    {"ST_CHARGEBACK", ST_CHARGEBACK},     {"ST_ADJREVERSE", ST_ADJREVERSE},
    {"ST_REBATE", ST_REBATE},     {"ST_VOLREBATE", ST_VOLREBATE},
    {"ST_LOYALTY", ST_LOYALTY},     {"ST_GROWTHINC", ST_GROWTHINC},
    {"ST_REFERRAL", ST_REFERRAL},     {"ST_DEPOSITSET", ST_DEPOSITSET},
    {"ST_RECVAGE", ST_RECVAGE},     {"ST_BADDEBT", ST_BADDEBT},
    {"ST_DEBTNET", ST_DEBTNET},     {"ST_COLLATERAL", ST_COLLATERAL},
    {"ST_RECVSTAT", ST_RECVSTAT},     {"ST_VATDETAIL", ST_VATDETAIL},
    {"ST_WHTDETAIL", ST_WHTDETAIL},     {"ST_TAXSUMMARY", ST_TAXSUMMARY},
    {"ST_SUPPLYCALC", ST_SUPPLYCALC},     {"ST_VATADJUST", ST_VATADJUST},
    {"ST_PRECONFIRM", ST_PRECONFIRM},     {"ST_LOCKBATCH", ST_LOCKBATCH},
    {"ST_UNLOCK", ST_UNLOCK},     {"ST_APPROVEALL", ST_APPROVEALL},
    {"ST_WORKFLOW", ST_WORKFLOW},     {"ST_GRPROLLUP", ST_GRPROLLUP},
    {"ST_GRPALLOC", ST_GRPALLOC},     {"ST_CHAINSET", ST_CHAINSET},
    {"ST_DISPUTERSV", ST_DISPUTERSV},     {"ST_APPEALSTAT", ST_APPEALSTAT},
    {"ST_VANDETAIL", ST_VANDETAIL},     {"ST_RELAYSPLIT", ST_RELAYSPLIT},
    {"ST_GRADESTAT", ST_GRADESTAT},     {"ST_MONTHSTAT", ST_MONTHSTAT},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) { userlog("st_svr: tpopen FAIL: %s", tpstrerror(tperrno)); return -1; }
    for (i = 0; SVCS[i].name; i++)
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("st_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    userlog("st_svr: %d st services advertised, RM opened", i);
    return 0;
}

void tpsvrdone(void) { tpclose(); userlog("st_svr: tpsvrdone"); }

/* vim: set ts=4 sw=4 et smartindent: */
