#ifndef Datenbank_H
#define Datenbank_H

#include <sql.h>
#include <Text.h>
#include <InitDatei.h>

using namespace Framework;
using namespace sql;

namespace Admin_Recht
{
    const int MSStarten = 1;
    const int MSBeenden = 2;
}

struct ServerData
{
    int id;
    Text name;
    Text ip;
    unsigned short port;
    unsigned short adminPort;
    Text status;
};

struct ServerDetails
{
    Text name;
    Text ip;
    unsigned short port;
    unsigned short adminPort;
    int tasks;
    int maxTasks;
};

class MSDatenbank : public virtual ReferenceCounter
{
private:
    Datenbank *datenbank;
    CRITICAL_SECTION ths;

public:
    // Konstruktor
    MSDatenbank( InitDatei *zDat );
    // Detruktor
    ~MSDatenbank();
    // nicht constant
    void lock();
    void unlock();
    int istAdministrator( const char *name, const char *passwort );
    bool adminHatRecht( int id, int recht );
    unsigned int getNextClientId();
    Text *getKlientKey( int cId );
    bool proveRegisteredClient( unsigned int num );
    int *unregisterClient( unsigned int num, int *len );
    int suchPatchServer( unsigned int client );
    int suchRegisterServer( unsigned int client );
    int suchLoginServer( unsigned int client );
    int suchInformationServer( unsigned int client );
    int suchChatServer( unsigned int client );
    int suchAnmeldungServer( unsigned int client );
    int suchErhaltungServer( unsigned int client );
    int suchShopServer( unsigned int client );
    int suchNewsServer( unsigned int client );
    int suchMinigameServer( unsigned int client );
    unsigned char *getServerPortIp( int sId );
    int logoutKlient( int klientId, Array< int > *ret );
    bool getSpielServerPortIp( int spielErstelltId, unsigned short *port, Text *ip );
    int getSpielerAusGruppe( int gruppeId, Array< int > *accountId );
    int kickSpielerAusGruppe( int gruppeId, int accountId );
    bool getChatServerPortIp( int accountId, unsigned short *port, Text *ip );
    int getGruppeAdmin( int gruppeId );
    int getSpielerAusChatroom( int chatroomId, Array< int > *accountId );
    int getChatroomAdmin( int chatroomId );
    int clientistEingeloggt( int clientId );
    bool getPatchServer( int client, Text *ip, int *port );
    bool getRegisterServer( int client, Text *ip, int *port );
    bool getLoginServer( int client, Text *ip, int *port );
    bool getInformationServer( int client, Text *ip, int *port );
    bool getChatServer( int client, Text *ip, int *port );
    bool getAnmeldungServer( int client, Text *ip, int *port );
    bool getSpielServer( int client, Text *ip, int *port );
    bool getShopServer( int client, Text *ip, int *port );
    bool getNewsServer( int client, Text *ip, int *port );
    bool getHistorieServer( int client, Text *ip, int *port );
    bool getKartenServer( int client, Text *ip, int *port );
    bool getEditorServer( int client, Text *ip, int *port );
    bool getMinigameServer( int client, Text *ip, int *port );
    bool getPatchServerList( Array< ServerData * > *list );
    bool getPatchServerDetails( int id, ServerDetails *details );
};

#endif