#pragma once

#include <QObject>
#include <QDomElement>
#include "android/xml/Node.h"
#include "db/AccountInfo.h"
#include "db/TransactionInfo.h"

class ScreenXmlParser final : public QObject {
    Q_OBJECT

public:
    explicit ScreenXmlParser(QObject *parent = nullptr);

    ~ScreenXmlParser() override;

    Node tryToFindBannerOrDialog(int width, int height);

    Node tryToFindSecurityBanner();

    Node findTextNode(const QString &text);

    Node findTextNode(const QString &text, int x1, int y1, int x2, int y2);

    Node findFirstEditText();

    Node findButtonNode(const QString &text, bool contains);

    bool isHomeScreen();


    QList<Node> tryToFindPinCode(const QString &pinCode, const QString &title);

    QList<Node> getLast2DaysTransactions();

    void parseAndSaveXml(const QString &xml);

    TransactionInfo parseTransactionInfoHistory(int screenWidth, int screenHeight);
    TransactionInfo parseTransactionInfo(int screenWidth, int screenHeight);

    QList<TransactionInfo> parseTodayAndYesterdayReportHistory();

    QList<TransactionInfo> parseTodayAndYesterdayHistory();


    QList<QPair<AccountInfo, Node> > parseAccountsInfo();

    void test();

private:
    QList<Node> m_nodes;
    QDomElement m_xml;

    QList<Node> findPinCodeNodes(const QString &pinCode);
};
