#ifndef DCANTISPAM_H
#define DCANTISPAM_H

#include <QObject>
#include <QList>

enum AntiSpamObjectState {
    eIN_BLACK = 0,
    eIN_GRAY,
    eIN_WHITE
};

class DCAntiSpam : public QObject {
    Q_OBJECT

public:
    DCAntiSpam();
    virtual ~DCAntiSpam();

    bool isInBlack(QString);
    bool isInWhite(QString);
    bool isInGray(QString);
    bool isInAny(QString);

    void move(QString, AntiSpamObjectState);

    void addToBlack(QList<QString> &list);
    void addToWhite(QList<QString> &list);
    void addToGray(QList<QString> &list);
    void remFromBlack(QList<QString> &list);
    void remFromWhite(QList<QString> &list);
    void remFromGray(QList<QString> &list);
    void clearBlack();
    void clearGray();
    void clearWhite();
    void clearAll();

    QList<QString> getBlack();
    QList<QString> getGray();
    QList<QString> getWhite();

    void loadSettings();
    void saveSettings();
    void loadLists();
    void saveLists();

    QString getPhrase() const;
    void setPhrase(QString &phrase);
    QList<QString> getKeys();
    void setKeys(QList<QString> &keys);

    void setAttempts(int);
    int  getAttempts() const;

    static void SetInstance(DCAntiSpam *);
    static DCAntiSpam *Instance();

private:

    inline void addToList(QList<QString>&, QList<QString>&);
    inline void remFromList(QList<QString>&, QList<QString>&);

    void loadBlack();
    void loadWhite();
    void loadGray();
    void saveBlack();
    void saveWhite();
    void saveGray();


    void readFile(QString, QList<QString>&);
    void saveFile(QString, QList<QString>&);

    QList<QString> white_list, black_list, gray_list;

    QString phrase;
    QList<QString> keys;
    int try_count;

    static DCAntiSpam *g_pAntiSpam;

public slots:

    /** */
    void slotObjectChangeState(QString obj, AntiSpamObjectState from, AntiSpamObjectState to);

};

namespace DC {
    class DCAntiSpam;
}

#endif // DCANTISPAM_H
