#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 AppSStarten = 57;
    const int AppSBeenden = 58;
}

class AppSDatenbank
{
private:
    Datenbank *datenbank;
    CRITICAL_SECTION ths;
    int ref;

public:
    // Konstruktor
    AppSDatenbank( InitDatei *zDat );
    // Detruktor
    ~AppSDatenbank();
    // nicht constant
    void lock();
    void unlock();
    int istAdministrator( const char *name, const char *passwort );
    bool adminHatRecht( int id, int recht );
    Text *getKey();
    int login( char *name, char *passwort );
    bool istNeu( int account );
    int getWeltBloeckeScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getWeltMauerScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getWeltFarbenScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getWeltFangenScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getWeltRennenScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getWeltGesamtScore( int anz, Array< int > *score, RCArray< Text > *namen );
    int getBloeckeScore( int account );
    int getMauerScore( int account );
    int getMauerZeit( int account, int level );
    int getFarbenScore( int account );
    int getFangenScore( int account );
    int getRennenScore( int account );
    int getGesamtScore( int account );
    void setBloeckeScore( int account, int score );
    void setFarbenScore( int account, int score );
    void setFangenScore( int account, int score );
    void setRennenScore( int account, int score );
    void setMauerZeit( int account, int level, int zeit );
    void calkMauerScore( int account );
    void calkGesamtScore( int account );
    int pruefNeuAccount( const char *name, const char *eMail );
    bool neuAccount( const char *name, const char *pass, const char *geheim, const char *eMail, const char *gebDatum, InitDatei *zIni );
    void markballsFinish( int level, int sek, int account, char *device, int diff, int kupfer, int gId );
    int getMarkballsScore( Array< int > *level, Array< int > *score, RCArray< Text > *name, int diff );
    int getMarkballsScore( Array< int > *level, Array< int > *score, int diff );
    void deviceAccount( char *device, int account );
    int getGegenstaende( int accountId, char *device, Array< int > *gId, Array< int > *diff );
    int getKupfer( int accountId );
    int getMarkballsFortschritt( int accountId, char *device, Array< int > *f );
    void addKupfer( int account, int kupfer );
    bool getFreeAds( int account );
    // Reference Counting
    AppSDatenbank *getThis();
    AppSDatenbank *release();
};

#endif