/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Web Feeds is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include "feedclassifiersmodel.h"

namespace NewsBlur
{
/*!
  \class FeedClassifiersModel
  \brief The FeedClassifiersModel class provides a model for editing
  FeedClassifiers objects.
*/
/*!
  \property FeedClassifiersModel::feedClassification
  The current classification of the feed.
*/
/*!
  \property FeedClassifiersModel::newTitleClassifier
  The classification of the newly added title.
*/
/*!
  \property FeedClassifiersModel::feedTitle
  The title of the feed.
*/

/*!
  Constructs a FeedClassifiersModel object with the given \a parent.
*/
FeedClassifiersModel::FeedClassifiersModel(QObject *parent)
    : QObject(parent),
      m_feedClassification(NewsBlurEnum::CvNeutralClassifier),
      m_newTitleClassifier(NewsBlurEnum::CvNeutralClassifier)
{
}

/*!
  Returns the current feed classifiers.
*/
FeedClassifiers FeedClassifiersModel::classifiers() const
{
    FeedClassifiers ret;
    if((m_newTitleClassifier != NewsBlurEnum::CvNeutralClassifier)
            && !m_newTitleClassifierText.trimmed().isEmpty())
        m_titles.insert(m_newTitleClassifierText.trimmed(), m_newTitleClassifier);
    ret.setTitleClassifiers(m_titles);
    ret.setAuthorClassifiers(m_authors);
    ret.setTagClassifiers(m_tags);
    ret.setFeedClassifier(m_feedClassification);
    return ret;
}

/*!
  \sa FeedClassifiersModel::classifiers
*/
void FeedClassifiersModel::setClassifiers(const FeedClassifiers &classifierSet)
{
    m_titles = classifierSet.titleClassifiers();
    m_tags = classifierSet.tagClassifiers();
    m_authors = classifierSet.authorClassifiers();
    m_feedClassification = classifierSet.feedClassifier();
}

QString FeedClassifiersModel::feedTitle() const
{
    return m_feedTitle;
}

void FeedClassifiersModel::setFeedTitle(const QString &title)
{
    m_feedTitle = title;
    emit feedTitleChanged();
}

/*!
  Returns the list of story title that can be classified.
*/
QStringList FeedClassifiersModel::titles() const
{
    return m_titles.keys();
}

/*!
  Returns the list of tags that can be classified.
*/
QStringList FeedClassifiersModel::tags() const
{
    return m_tags.keys();
}

/*!
  Returns the list of authors that can be classified.
*/
QStringList FeedClassifiersModel::authors() const
{
    return m_authors.keys();
}

/*!
  Returns the classificatio of the given story \a title.
*/
int FeedClassifiersModel::titleClassification(const QString &title) const
{
    return m_titles.value(title);
}

/*!
  Sets the \a classification of the given story \a title.
*/
void FeedClassifiersModel::setTitleClassification(const QString &title, int classification)
{
    m_titles.insert(title, NewsBlurEnum::ClassifierValue(classification));
}

/*!
  Returns the classification of the given \a tag.
*/
int FeedClassifiersModel::tagClassification(const QString &tag) const
{
    return m_tags.value(tag);
}

/*!
  Sets the \a classification of the given \a tag.
*/
void FeedClassifiersModel::setTagClassification(const QString &tag, int classification)
{
    m_tags.insert(tag, NewsBlurEnum::ClassifierValue(classification));
}

/*!
  Returns the classification of the given \a author.
*/
int FeedClassifiersModel::authorClassification(const QString &author) const
{
    return m_authors.value(author);
}

/*!
  Sets the \a classification of the given \a author.
*/
void FeedClassifiersModel::setAuthorClassification(const QString &author, int classification)
{
    m_authors.insert(author, NewsBlurEnum::ClassifierValue(classification));
}

void FeedClassifiersModel::setFeedClassification(int classification)
{
    m_feedClassification = NewsBlurEnum::ClassifierValue(classification);
    emit feedClassificationChanged();
}

int FeedClassifiersModel::feedClassification() const
{
    return m_feedClassification;
}

int FeedClassifiersModel::newTitleClassifier() const
{
    return m_newTitleClassifier;
}

void FeedClassifiersModel::setNewTitleClassifier(int classification)
{
    m_newTitleClassifier = NewsBlurEnum::ClassifierValue(classification);
    emit newTitleClassifierChanged();
}

/*!
  Sets the \a text of the newly defined title classifier.
*/
void FeedClassifiersModel::setNewTitleClassifierText(const QString &text)
{
    m_newTitleClassifierText = text;
}
} // namespace NewsBlur
