#ifndef DATADIRECTORY_H
#define DATADIRECTORY_H

#include "datafile.h"
#include "src/view/inputchange.h"

class DataDirectory : public DataFile
{
    Q_OBJECT
public:
    explicit DataDirectory(QString path, QObject *parent = nullptr, bool fromDisk = false);
    ~DataDirectory();
public:
    DataFile *at(int);
    int of(DataFile *);
    int of(DataDirectory *);
    bool take(DataFile *);
    void append(DataFile *d);
    void filterAppend(DataFile *d) { m_oChildren << d; }
    int count() const;
    int counts() const { return m_oChildren.size(); }
    unsigned long total() const { return m_u64Dirs + m_u64Files; }
    unsigned long nSize() const { return m_u64NewDataSize; }
    bool isRoot() const { return m_bIsRoot; }
    bool canClean() const;
    bool duplicate(QString) const;
    void rename(QString, bool add = false);
    void updateChild(QString, QString);
    void clear();
    void clean();
    void copy();
    void *findChildByDisplay(QString, bool child = false);
    static void setFilterHidden(bool filter);
    bool filterHidden() const {
        // 暂不提供针对具体节点的隐藏属性，改为使用全局隐藏属性
        // return m_bFilterHidden;
        return g_bFilterHidden;
    }
    static void setFilterBrokenSymbolLinks(bool filter);
    bool filterBrokenSymbolLinks() const {
        // 暂不提供针对具体节点的过滤，改为使用全局配置
        // return m_bFilterBroken;
        return g_bFilterBroken;
    }
    static void setRepleaceSymbolLinks(bool filter);
    bool repleaceSymbolLinks() const {
        // 暂不提供针对具体节点的过滤，改为使用全局配置
        // return m_bRepleace;
        return g_bRepleace;
    }
    void execHidden(bool b = true);
    void execBroken(bool b = true);
    void execRepleace(bool b = true);
    void turnViewFilterFileToHidden();
    void turnViewFilterFileToBrokenSymbolLinks();
    void turnViewFilterFileToRepleaceSymbolLinks();
    int  CountOneLevelNotDiskFile();
public slots:
    void doSize(unsigned long, bool);
    void doDirectory(bool, DataFile *);
    void doFile(bool, DataFile *);
    void doChild(DataFile *, bool);
private:
    InputChange                 *inputchange;//界面
    bool                        m_bIsRoot;//是否为根节点
    bool                        m_bFilterHidden;//是否执行隐藏文件过滤
    bool                        m_bFilterBroken;//是否执行损坏连接文件过滤
    bool                        m_bRepleace;//是否执行连接文件替换
    unsigned long               m_u64Dirs;//当前文件夹下包含文件夹数量
    unsigned long               m_u64Files;//当前文件夹下包含文件数量
    unsigned long               m_u64NewDataSize;//当前文件夹下新添加文件大小
    QList<DataFile *>           m_oChildren;//当前文件夹下子文件
    QHash<QString, DataFile *>  m_oHashChildren;//当前文件夹下唯一子文件
    static bool g_bFilterHidden;//是否执行隐藏文件过滤
    static bool g_bFilterBroken;//是否执行损坏连接文件过滤
    static bool g_bRepleace;//是否执行连接文件替换
signals:
    void updateSize(unsigned long);
};

#endif // DATADIRECTORY_H
