#pragma once

#include <QObject>
#include "ScreenXmlParser.h"

class CommonScript : public QObject {
    Q_OBJECT

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

    ~CommonScript() override;

protected:
    virtual void doStart() = 0;

    // static method
    static bool inputPinCode(const QString &deviceId, const QList<Node> &pincode);

    bool goToAllProducts(
        const QString &deviceId,
        int width,
        int height
    );

    bool findAndTapOnAccount(const QString &deviceId, const QString &accountNumbers);

    void postAccountsData(const QList<QPair<AccountInfo, Node> > &accounts);

    void postNewTransactionData(const AccountInfo &account, const TransactionInfo &transaction);

    void updateTransactionData(
        const AccountInfo &account,
        int transactionId,
        TransactionStatus status,
        const QString &oldDesc,
        const QString &newDesc
    );

    Node swipeToButton(
        const QString &deviceId,
        const QString &text,
        int &counter, int width, int height
    );

    bool runAppAndGoToHomeScreen(
        const QString &deviceId,
        const QString &packageName,
        const QString &pinCode,
        int width,
        int height
    );

    bool tryToCloseAllBannersOnHomePage(
        const QString &deviceId, int width, int height
    );

    bool m_running = true;
    ScreenXmlParser xmlScreenParser;
    int m_counter = 0;

signals:
    void finished();

    void finishedWithResult(const QString &result);

public slots:
    virtual void start() final;

    virtual void stop() final;

private:
    Q_DISABLE_COPY(CommonScript);
};
