#ifndef SPOWERCAFE
#define SPOWERCAFE
#include "sservice.h"
#include "sfilteralgorithm.h"
#include "sinitializer.h"
class QString;
class QStringList;
class SPowercafe:public SService
{
public:
    struct stReal
    {
        QSet<QString> m_setRealAllUrl;
        QSet<QString> m_setRealBodyUrl;
        QMap<QString, int> m_mapRealReplyUniqueUrl; //multiple
    };

    struct stPowercafe
    {
        int category_num;
        int community_num;
        QString community_id;
        int bodycountall;
        int replycountall;
        int allcountall;
        int usercountall;
        int bodycountreal;
        int replycountreal;
        int allcountreal;
        int usercountreal;
        int rank;

        QString community_title;
        QString community_url;
        int platformname_num;
        QString platformname_name;

        stPowercafe():category_num(0), community_num(0), bodycountall(0), replycountall(0), allcountall(0), usercountall(0), bodycountreal(0),
            replycountreal(0), allcountreal(0), usercountreal(0), rank(0), platformname_num(0){}
    };

    struct stStatsPowCafeRank
    {
        QString community_id;
        QString community_title;
        int articlecountall;
        int articlecountreal;
        int usercountreal;
        QString subject;
        int rank;
        int company_num;
        stStatsPowCafeRank(): articlecountall(0), articlecountreal(0), usercountreal(0), rank(0), company_num(0){}
    };

    struct stBodyPowercafeMap
    {
        int num;
        int body_num;
        int community_num;
        int category_num;
        int realin;
        QString body_date;
        int platformname_num;
        stBodyPowercafeMap():num(0), body_num(0), community_num(0), category_num(0), realin(0), platformname_num(0){}
    };

    struct stReplyPowercafeMap
    {
        int num;
        int reply_num;
        int body_num;
        int community_num;
        int category_num;
        int realin;
        QString body_date;
        stReplyPowercafeMap():num(0), reply_num(0), body_num(0), community_num(0), category_num(0), realin(0) {}
    };

    class STPowercafe
    {
    private:
        SInitializer *m_pSInitializer;
        QList<stPowercafe> m_listMap;

    public:
        void setInitiaizer(SInitializer &_initializer){ m_pSInitializer = &_initializer; }
        void clear(){ m_listMap.clear(); }
        void makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory);
        bool uploadData(QSqlDatabase &_db, const int &_nCompany);
        bool changeTable(QSqlDatabase &_db, const int &_nCompany);

    };

    class SStatsPowCafeRank
    {
    private:
        SInitializer *m_pSInitializer;
        QList<stStatsPowCafeRank> m_listMap;

    public:
        void setInitiaizer(SInitializer &_initializer){ m_pSInitializer = &_initializer; }
        void clear(){ m_listMap.clear(); }
        void makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory);
        bool uploadData(QSqlDatabase &_db, const int &_nCompany);
    };

    class SBodyPowercafeMap
    {
    private:
        SInitializer *m_pSInitializer;
        QList<stBodyPowercafeMap> m_listMap;

    public:
        void setInitiaizer(SInitializer &_initializer){ m_pSInitializer = &_initializer; }
        void clear(){ m_listMap.clear(); }
        void makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory);
        bool uploadData(QSqlDatabase &_db, const int &_nCompany);
        bool changeTable(QSqlDatabase &_db, const int &_nCompany);
    };

    class SReplyPowercafeMap
    {
    private:
        SInitializer *m_pSInitializer;
        QList<stReplyPowercafeMap> m_listMap;

    public:
        void setInitiaizer(SInitializer &_initializer){ m_pSInitializer = &_initializer; }
        void clear(){ m_listMap.clear(); }
        void makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory);
        bool uploadData(QSqlDatabase &_db, const int &_nCompany);
        bool changeTable(QSqlDatabase &_db, const int &_nCompany);
    };

    struct isGreaterCountReal
    {
        bool operator()(const stPowercafe& first, const stPowercafe& second)
        {
            return first.allcountreal > second.allcountreal;
        }
        bool operator()(const stStatsPowCafeRank& first, const stStatsPowCafeRank& second)
        {
            return first.articlecountreal > second.articlecountreal;
        }
    };

    struct isGreaterCountAll
    {
        bool operator()(const stStatsPowCafeRank& first, const stStatsPowCafeRank& second)
        {
            return first.articlecountall > second.articlecountall;
        }
    };



private:
    SFilterAlgorithm m_SFilterAlgorithm;
    QMap<int, stReal> m_mapCategory;
    SBodyPowercafeMap m_SBodyPowercafeMap;
    SReplyPowercafeMap m_SReplyPowercafeMap;
    STPowercafe m_STPowercafe;
    SStatsPowCafeRank m_SStatsPowCafeRank;

public:
    virtual void setInitiaizer(SInitializer &_initializer);
    virtual bool uploadData(int _companyNum);
    virtual bool changeTable(int _companyNum);
    virtual bool makeCategory(SDatagroup &_datagroup, int _nCategory, const QList<SInitializer::stFilter> &_listFilter);
    virtual bool makeOverallCategory(int _categoryNum);
    virtual bool makeTable(SDatagroup &_datagroup);
};

#endif // SPOWERCAFE

