/*
 * Copyright 2022 KylinSoft Co., Ltd.
 *
 * 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 <https://www.gnu.org/licenses/>.
 */

#ifndef PROCESSINFO_H
#define PROCESSINFO_H

#include <QObject>
#include <QDebug>
#include "windowmanager/windowmanager.h"
#include <QApplication>
#include <QFile>
#include <QTimer>
#include <QThread>
#include <QProcess>
#include <QDir>
#include <fstream>
#include <iostream>

using namespace kdk;

/**
 * @brief The ProcessInfo class 保存应用进程信息的类
 * @Info 保存的信息包含（pid childrenPid status wids args tasks exe cmdline）
 * @author duchangfeng
 */
class ProcessInfo
{

public:
    enum AppStatus {
        ForegroundProcess,
        InvisibleProcess,
        CachedProcess,
    };

    bool operator== (const ProcessInfo &other) {
                    return other.pid == this->pid &&
                            other.childrenPid == this->childrenPid &&
                            other.status == this->status &&
                            other.wids == this->wids &&
                            other.args == this->args &&
                            other.tasks == this->tasks &&
                            other.exe == this->exe &&
                            other.cmdline == this->cmdline;
    }

    explicit ProcessInfo(qint64 pid, QList<qint64> childrenPid, AppStatus status, QList<WindowId> wids, QStringList args);

    qint64 getPid() const;

    QList<qint64> getChildrenPid() const;

    AppStatus getStatus() const;

    QList<kdk::WindowId> getWids() const;

    QStringList getArgs() const;

    QList<qint64> getTasks() const;

    QString getExe() const;

    QString getCmdline() const;  

    void setStatus(const AppStatus &appStatus);

    void setPid(const qint64 &appPid);

    void pushWids(const WindowId &wid);

    void removeWids(const WindowId &wid);

    void setWids(const QList<WindowId> &appWids);

private:
    qint64 pid;
    QList<qint64> childrenPid;
    AppStatus status;
    QList<WindowId> wids;
    QStringList args;
    QList<qint64> tasks;
    QString exe;
    QString cmdline;  

    void initProcessInfo(qint64 pid, QList<qint64> childrenPid, AppStatus status, QList<WindowId> wids, QStringList args);

    void setChildrenPid(const qint64 &appPid);

//    void setWids(const QList<WId> &appWids);

    void setArgs(const QStringList &appArgs);

    void setTasks(const qint64 &appPid);

    void setExe(const qint64 &appPid);

    void setCmdline(const qint64 &appPid);

};

#endif // PROCESSINFO_H
