/*
    Quickddit - Reddit client for mobile phones
    Copyright (C) 2014  Dickson Leong
    Copyright (C) 2015-2020  Sander van Grieken

    This program 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.

    This program 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 this program.  If not, see [http://www.gnu.org/licenses/].
*/

#ifndef PARSER_H
#define PARSER_H

#include <QtCore/QList>
#include <QtCore/QPair>
#include <QtCore/QByteArray>
#include <QtCore/QVariantList>
#include <QString>

#include "thing.h"

class LinkObject;
class CommentObject;
class SubredditObject;
class MultiredditObject;
class MessageObject;
class UserObject;

template<typename T>
class Listing : public QList<T>
{
public:
    Listing() : m_hasMore(false) {}

    bool hasMore() const { return m_hasMore; }
    void setHasMore(bool hasMore) { m_hasMore = hasMore; }

private:
    bool m_hasMore;
};

namespace Parser
{
// generic
QVariantList parseList(const QByteArray &json);
QVariantMap parseMap(const QByteArray &json);

QList<QString> parseErrors(const QByteArray &json);

QStringList parseListOfNames(const QByteArray &json);

Listing<LinkObject> parseLinkList(const QByteArray &json);
Listing<LinkObject> parseDuplicates(const QByteArray &json);
LinkObject parseLinkEditResponse(const QByteArray &json);

QPair< LinkObject, QList<CommentObject> > parseCommentList(const QByteArray &json);
CommentObject parseNewComment(const QByteArray &json);
QList<CommentObject> parseMoreChildren(const QByteArray &json, const QString &linkAuthor, int depth);

SubredditObject parseSubreddit(const QByteArray &json);
Listing<SubredditObject> parseSubredditList(const QByteArray &json);

QList<MultiredditObject> parseMultiredditList(const QByteArray &json);
QString parseMultiredditDescription(const QByteArray &json);

Listing<MessageObject> parseMessageList(const QByteArray &json);

UserObject parseUserAbout(const QByteArray &json);
Listing<Thing*> parseUserThingList(const QByteArray &json);

Listing<LinkObject> parseDuplicateList(const QByteArray &json);

// non-reddit
QList< QPair<QString, QString> > parseImgurImages(const QByteArray &json);
}

#endif // PARSER_H
