// ################################
// ##    Pripojeni k databazi    ##
// ##           :-O-:            ##
// ################################

#pragma once
#ifndef DBCONN_H
#define DBCONN_H

#include "common.h"

#include <string>

#include "ibpp/core/ibpp.h"

// ################################

class dbFortressList
{
private:
    IBPP :: Statement fListSELECT_;
    IBPP :: Statement fListDELETE_;
    IBPP :: Statement fListINSERT_;
public:
    void prepare(const std :: string& sqlSELECT, const std :: string& sqlDELETE, 
        const std :: string& sqlINSERT, IBPP :: Database& db, IBPP :: Transaction& tr);

	inline IBPP :: Statement&    getFL_SELECT(void)         { return fListSELECT_;              };
    inline IBPP :: Statement&    getFL_DELETE(void)         { return fListDELETE_;              };
    inline IBPP :: Statement&    getFL_INSERT(void)         { return fListINSERT_;              };

    void close(void);
};

// ################################

class dbRealmList
{
private:
    IBPP :: Statement fListSELECT_;
    IBPP :: Statement fListDELETE_;
    IBPP :: Statement fListINSERT_;
public:
    void prepare(const std :: string& sqlSELECT, const std :: string& sqlDELETE, 
        const std :: string& sqlINSERT, IBPP :: Database& db, IBPP :: Transaction& tr);

	inline IBPP :: Statement&    getFL_SELECT(void)         { return fListSELECT_;              };
    inline IBPP :: Statement&    getFL_DELETE(void)         { return fListDELETE_;              };
    inline IBPP :: Statement&    getFL_INSERT(void)         { return fListINSERT_;              };

    void close(void);
};

// ################################

enum settings
{
    STT_NORMAL_TIME = 1,
    STT_GAME_TIME   = 2
};

// ################################
// ################################

class dbClient
{
private:
	/* zakladni databazove veci */
	IBPP :: Database db_;
	IBPP :: Transaction tr_;

	/* dotazy */

	/* Scientific tree */
	IBPP :: Statement scTreeQueryINSERT_;
	IBPP :: Statement scTreeQueryDELETE_;
	IBPP :: Statement scTreeQuerySELECT_;
	IBPP :: Statement scTreeQueryUPDATE_;

	/* Item patterns */
	IBPP :: Statement itemPatternQuerySELECT_;

	/* Items */
	IBPP :: Statement itemsQueryINSERT_;
	IBPP :: Statement itemsQueryDELETE_;
	IBPP :: Statement itemsQuerySELECT_;
	IBPP :: Statement itemsQueryUPDATE_;

    /* Fortress */
    IBPP :: Statement fortressQueryINSERT_;
    IBPP :: Statement fortressQueryDELETE_;
    IBPP :: Statement fortressQuerySELECT_;
    IBPP :: Statement fortressQueryUPDATE_;

    /* Space objects */
    IBPP :: Statement spaceObjQueryINSERT_;
    IBPP :: Statement spaceObjQueryDELETE_;
    IBPP :: Statement spaceObjQuerySELECT_;
    IBPP :: Statement spaceObjQueryUPDATE_;
    IBPP :: Statement spaceObjQuerySELSUB_;

    /* Fortress classes */
    IBPP :: Statement fortressClassQueryINSERT_;
    IBPP :: Statement fortressClassQueryDELETE_;
    IBPP :: Statement fortressClassQuerySELECT_;
    IBPP :: Statement fortressClassQueryUPDATE_;

    /* Player realms */
    IBPP :: Statement playerRealmQueryINSERT_;
    IBPP :: Statement playerRealmQueryDELETE_;
    IBPP :: Statement playerRealmQuerySELECT_;
    IBPP :: Statement playerRealmQueryUPDATE_;
    IBPP :: Statement playerRealmQueryLOGIN_;
    IBPP :: Statement playerRealmQueryBSLIST_;

    dbRealmList playerRealmDS_;

    /* fortress listy */
    dbFortressList F_HAN_HANGARS_;
    dbFortressList F_PRO_PROBES_;
    dbFortressList F_WAR_STORAGE_;
    dbFortressList F_WEP_DRONEMISSILELAUNCHERS_;
    dbFortressList F_WEP_LASERGUNS_;
public:
	bool connect(const std :: string& server, const std :: string& database, 
		const std :: string& username, const std :: string& password);
	void commit(void);
	void disconnect(void);

	inline IBPP :: Statement&    getScTreeQueryINSERT(void)         { return scTreeQueryINSERT_;              };
	inline IBPP :: Statement&    getScTreeQueryDELETE(void)         { return scTreeQueryDELETE_;              };
	inline IBPP :: Statement&    getScTreeQuerySELECT(void)         { return scTreeQuerySELECT_;              };
	inline IBPP :: Statement&    getScTreeQueryUPDATE(void)         { return scTreeQueryUPDATE_;              };

	inline IBPP :: Statement&    getItemPatternQuerySELECT(void)    { return itemPatternQuerySELECT_;         };

	inline IBPP :: Statement&    getItemsQueryINSERT(void)          { return itemsQueryINSERT_;               };
	inline IBPP :: Statement&    getItemsQueryDELETE(void)          { return itemsQueryDELETE_;               };
	inline IBPP :: Statement&    getItemsQuerySELECT(void)          { return itemsQuerySELECT_;               };
	inline IBPP :: Statement&    getItemsQueryUPDATE(void)          { return itemsQueryUPDATE_;               };

    inline IBPP :: Statement&    getFortressQueryINSERT(void)       { return fortressQueryINSERT_;            };
    inline IBPP :: Statement&    getFortressQueryDELETE(void)       { return fortressQueryDELETE_;            };
    inline IBPP :: Statement&    getFortressQuerySELECT(void)       { return fortressQuerySELECT_;            };
    inline IBPP :: Statement&    getFortressQueryUPDATE(void)       { return fortressQueryUPDATE_;            };

    inline IBPP :: Statement&    getSpaceObjQueryINSERT(void)       { return spaceObjQueryINSERT_;            };
    inline IBPP :: Statement&    getSpaceObjQueryDELETE(void)       { return spaceObjQueryDELETE_;            };
    inline IBPP :: Statement&    getSpaceObjQuerySELECT(void)       { return spaceObjQuerySELECT_;            };
    inline IBPP :: Statement&    getSpaceObjQueryUPDATE(void)       { return spaceObjQueryUPDATE_;            };
    inline IBPP :: Statement&    getSpaceObjQuerySELSUB(void)       { return spaceObjQuerySELSUB_;            };

    inline IBPP :: Statement&    getFortressClassQueryINSERT(void)  { return fortressClassQueryINSERT_;       };
    inline IBPP :: Statement&    getFortressClassQueryDELETE(void)  { return fortressClassQueryDELETE_;       };
    inline IBPP :: Statement&    getFortressClassQuerySELECT(void)  { return fortressClassQuerySELECT_;       };
    inline IBPP :: Statement&    getFortressClassQueryUPDATE(void)  { return fortressClassQueryUPDATE_;       };

    inline IBPP :: Database&     getDatabase(void)                  { return db_;                             };
    inline IBPP :: Transaction&  getTransaction(void)               { return tr_;                             };

    inline dbFortressList&       getHAN_HANGARS_fortress_list(void) { return F_HAN_HANGARS_;                  };
    inline dbFortressList&       getPRO_PROBES_fortress_list(void)  { return F_PRO_PROBES_;                   };
    inline dbFortressList&       getWAR_STORAGE_fortress_list(void) { return F_WAR_STORAGE_;                  };
    inline dbFortressList&       getWEP_DRONE_fortress_list(void)   { return F_WEP_DRONEMISSILELAUNCHERS_;    };
    inline dbFortressList&       getWEP_LASER_fortress_list(void)   { return F_WEP_LASERGUNS_;                };

    inline IBPP :: Statement&    getPlayerRealmQueryINSERT(void)    { return playerRealmQueryINSERT_;         };
    inline IBPP :: Statement&    getPlayerRealmQueryDELETE(void)    { return playerRealmQueryDELETE_;         };
    inline IBPP :: Statement&    getPlayerRealmQuerySELECT(void)    { return playerRealmQuerySELECT_;         };
    inline IBPP :: Statement&    getPlayerRealmQueryUPDATE(void)    { return playerRealmQueryUPDATE_;         };
    inline IBPP :: Statement&    getPlayerRealmQueryLOGIN(void)     { return playerRealmQueryLOGIN_;          };
    inline IBPP :: Statement&    getPlayerRealmQueryBSLIST(void)    { return playerRealmQueryBSLIST_;         };
    inline dbRealmList&          getPlayerRealmDSList(void)         { return playerRealmDS_;                  };

    double                       getDoubleSettings(const settings);
    signed long long             getIntegerSettings(const settings);
    void                         setDoubleSettings(const settings, double value);
    void                         setIntegerSettings(const settings, signed long long value);
};



#endif
