#ifndef DUPLICATEDNODEITEM_H
#define DUPLICATEDNODEITEM_H

#include "DuplicatedNodeInfo.h"
#include "FileFolderAttributes.h"
#include "megaapi.h"
#include "QTMegaRequestListener.h"

#include <QDateTime>
#include <QFutureWatcher>
#include <QPointer>
#include <QWidget>

#include <memory>

namespace Ui {
class DuplicatedNodeItem;
}

/*
 * BASE CLASS
*/
class DuplicatedNodeItem : public QWidget
{
    Q_OBJECT

public:
    DuplicatedNodeItem(QWidget *parent = nullptr);
    virtual ~DuplicatedNodeItem();

    virtual void setInfo(std::shared_ptr<DuplicatedNodeInfo> info, NodeItemType type);

    NodeItemType getType(){return mType;}
    void setType(NodeItemType type);

    void setDescription(const QString& description);
    void showLearnMore(const QString& url);

signals:
    void actionClicked();

protected:
    NodeItemType mType;
    std::shared_ptr<DuplicatedNodeInfo> mInfo;
    qint64 mNodeSize;

    void fillUi();
    virtual QString getNodeName() = 0;
    virtual bool isFile() const = 0;

    void setModifiedTime(const QDateTime &dateTime);
    void setSize(qint64 size);

    bool isValid() const;

protected slots:
    void on_bAction_clicked();

private slots:
    void rebuildLearnMore();

private:
    Ui::DuplicatedNodeItem *ui;
    QString mLearnMoreUrl;

    void setActionAndTitle(const QString& text);
};

/*
 * REMOTE IMPLEMENTATION CLASS
 * USE TO SHOW THE REMOTE NODE INFO
*/
class DuplicatedRemoteItem : public DuplicatedNodeItem
{
    Q_OBJECT
public:
    DuplicatedRemoteItem(QWidget *parent = nullptr);
    ~DuplicatedRemoteItem();

    void setInfo(std::shared_ptr<DuplicatedNodeInfo> info, NodeItemType type) override;
    void setInfoSpecifyingHandle(std::shared_ptr<DuplicatedNodeInfo> info, mega::MegaHandle handle,  NodeItemType type);

    std::shared_ptr<mega::MegaNode> getNode();

protected:
    QString getNodeName() override;
    bool isFile() const override;

private:
    mega::QTMegaRequestListener* mListener;
    QPointer<RemoteFileFolderAttributes> mFolderAttributes;
};

/*
 * LOCAL IMPLEMENTATION CLASS
 * USE TO SHOW THE LOCAL NODE INFO
*/
class DuplicatedLocalItem : public DuplicatedNodeItem
{
    Q_OBJECT

public:
    explicit DuplicatedLocalItem(QWidget *parent = nullptr);
    virtual ~DuplicatedLocalItem();

    void setInfo(std::shared_ptr<DuplicatedNodeInfo> info, NodeItemType type) override;

protected:
    QString getNodeName() override;
    bool isFile() const override;

private:
    QString getFullFileName(const QString& path, const QString& fileName);

    QPointer<LocalFileFolderAttributes> mFolderAttributes;
};

/*
 * RENAME IMPLEMENTATION FOR LOCAL NODES
 * USE TO SHOW THE RENAME OPTION
*/
class DuplicatedRenameItem : public DuplicatedLocalItem
{
    Q_OBJECT

public:
    explicit DuplicatedRenameItem(QWidget *parent = nullptr);
    ~DuplicatedRenameItem() = default;

    void setRenameInfo(std::shared_ptr<DuplicatedNodeInfo> conflict);

protected:
    QString getNodeName() override;
};


#endif // DUPLICATEDNODEITEM_H
