// dbexport.h - MySQL export interface for mw4print
//
// Connects to an external MySQL server and writes match results after each
// print job.  MySQL is loaded at runtime via late binding (libmysql.dll) so
// no MySQL SDK is required at compile time.
//
// Config is stored in mw4print.ini next to the exe:
//   [MySQLExport]
//   Enabled=0
//   Host=192.168.1.100
//   Port=3306
//   Database=firestorm_stats
//   Username=mw4
//   Password=
//   ExportEvents=0    (1 = also export per-event SRecScore rows)
//

#ifndef __DBEXPORT_H__
#define __DBEXPORT_H__

// ---- Config struct -------------------------------------------------------

struct SDBConfig
{
    bool  bEnabled;
    char  szHost[256];
    int   nPort;
    char  szDatabase[64];
    char  szUsername[64];
    char  szPassword[64];
    bool  bExportEvents;   // export individual SRecScore events (can be many rows)
};

extern SDBConfig g_dbConfig;

// ---- Public API ----------------------------------------------------------

// Load / save config from mw4print.ini in the app directory.
void DB_LoadConfig();
void DB_SaveConfig();

// Try to open a connection using current g_dbConfig, run a trivial query,
// then disconnect.  Returns true on success; on failure fills pszError
// (up to nErrBufSize bytes) with the MySQL error string.
bool DB_TestConnection(char* pszError, int nErrBufSize);

// Export one completed match to the database.  Called from
// CRecScoreFull::DoPrint() just before PrintDlg().
// Returns true on success.
bool DB_ExportMatch(
    const CRecScoreFull&           rsf,
    PCRecScoreObject               aRSOs[],
    int                            nPlayers,
    const int                      naTeams[8],
    int                            nTeamCount,
    const MWNetMissionParameters&  params
);

#endif // __DBEXPORT_H__
