#ifndef __DATABASE_H__
#define __DATABASE_H__

#include "DataStructure.h"
#include <list>
#include <string>

typedef struct sqlite3 sqlite3;

namespace Older {
class Database {
public:
    bool open(const std::string &path);
    void upsertVisitRecord(const std::string &url, const std::string &visitorUuid, const std::string &userAgent,
                           int64_t viewTime);
    VisitorStats visitorStats(const std::string &url);

    std::list<VisitorStats> mostViewedUrls(int n);
    std::list<VisitorStats> latestViewedUrls(int n);
    SiteStats siteStats();
    std::list<VisitRecord> visitRecords();
    bool removeVisitRecord(int id);
    void createUser(const Account &account);
    Account user(const std::string &identifier) const;
    Account user(int64_t id) const;

protected:
    void createVisitAnalysisTable();
    void createUsersTable();
    void initialize();

private:
    sqlite3 *m_sqlite = nullptr;
};
} // namespace Older

#endif // __DATABASE_H__