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

    struct stSpammer
    {
        int id_num;
        int category_num;
        QString id_id;
        int nicknamecount;
        int bodycount;
        int replycount;
        double spammervalue;
        int rank;
        QString platformname_name;
        int platformname_num;
        stSpammer():id_num(0), category_num(0), nicknamecount(0), bodycount(0), replycount(0), rank(0), spammervalue(0.0), platformname_num(0){}

    };

    struct stStatsSpaSpammerRank
    {
        int id_num;
        QString id_id;
        QString platformname_name;
        int nicknamecount;
        int bodycount;
        int replycount;
        double spammervalue;
        int rank;
        QString subject;
        int company_num;
        stStatsSpaSpammerRank():id_num(0),nicknamecount(0),bodycount(0),replycount(0),rank(0), spammervalue(0.0){}

    };

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

    };

    struct stReplySpammerMap
    {
        int num;
        int reply_num;
        int body_num;
        int id_num;
        int category_num;
        QString body_date;
        stReplySpammerMap():num(0), body_num(0), reply_num(0), id_num(0), category_num(0){}
    };

    struct stSpammerScore
    {
        int body;
        int reply;
        int id_num;
        QSet<QString> nickname;
        stSpammerScore():body(0),reply(0){}
    };

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

    };

    class SStatsSpaSpammerRank
    {
    private:
        SInitializer *m_pSInitializer;
        QList<stStatsSpaSpammerRank> 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 SBodySpammerMap
    {
    private:
         SInitializer *m_pSInitializer;
         QList<stBodySpammerMap> m_listMap;
    public:
        void setInitiaizer(SInitializer &_initializer){ m_pSInitializer = &_initializer; }
        void clear(){ m_listMap.clear(); }
        void makeTable(SDatagroup &_datagroup, const QMap<int, stReal>& _mapCategory ,QSet<int>& setSpammer);
        bool uploadData(QSqlDatabase &_db, const int &_nCompany);
        bool changeTable(QSqlDatabase &_db, const int &_nCompany);
    };

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

    struct isGreaterSpammerValue
    {
        bool operator()(const stSpammer& first, const stSpammer& second) const
        {
            return first.spammervalue > second.spammervalue;
        }

        bool operator()(const stStatsSpaSpammerRank& first, const stStatsSpaSpammerRank& second) const
        {
            return first.spammervalue > second.spammervalue;
        }
    };

private:
    SFilterAlgorithm m_SFilterAlgorithm;
    QMap<int, stReal> m_mapCategory;
    STSpammer m_STSpammer;
    SStatsSpaSpammerRank m_SStatsSpaSpammerRank;
    SBodySpammerMap m_SBodySpammerMap;
    SReplySpammerMap m_SReplySpammerMap;
    QSet<int> m_setSpammer;

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 // SSPAMMER

