/*
 * Copyright (C) 2026, 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/>.
 *
 * Authors: iaom <zhangpengfei@kylinos.cn>
 */

#ifndef UKUI_WORKSPACE_MANAGER_H
#define UKUI_WORKSPACE_MANAGER_H

#include <QObject>
#include <QList>
#include <KWayland/Client/event_queue.h>

struct kywc_workspace_manager_v1;
struct kywc_workspace_v1;
using namespace KWayland::Client;

namespace UkuiQuick::WaylandClient {

namespace Test {
class UkuiWorkspaceManagerTest;
}
class UkuiWorkspace;

class UkuiWorkspaceManager : public QObject
{
    Q_OBJECT
public:
    explicit UkuiWorkspaceManager(QObject *parent = nullptr);
    ~UkuiWorkspaceManager() override;

    bool isValid() const;
    void release();
    void destroy();
    void setup(kywc_workspace_manager_v1 *manager);
    void setEventQueue(EventQueue *queue);
    EventQueue *eventQueue() const;

    void createWorkspace(const QString &name, uint32_t position);
    void stop();

    QList<UkuiWorkspace *> workspaces() const;

Q_SIGNALS:
    void workspaceCreated(UkuiQuick::WaylandClient::UkuiWorkspace *workspace, const QString &uuid);
    void done();
    void interfaceAboutToBeReleased();
    void interfaceAboutToBeDestroyed();
    void removed();

private:
    class Private;
    QScopedPointer<Private> d;
};

class UkuiWorkspace : public QObject
{
    Q_OBJECT
public:
    ~UkuiWorkspace() override;

    void setup(kywc_workspace_v1 *workspace);
    void release();
    void destroy();
    bool isValid() const;

    QString name() const;
    uint32_t position() const;
    bool isActivated() const;
    QString uuid() const;

Q_SIGNALS:
    void nameChanged(const QString &name);
    void positionChanged(uint32_t position);
    void activated();
    void deactivated();
    void removed();

public Q_SLOTS:
    void setPosition(uint32_t position);
    void activate();
    void remove();
    void setName(const QString &name);

private:
    friend class UkuiWorkspaceManager;
    friend class Test::UkuiWorkspaceManagerTest;
    explicit UkuiWorkspace(QObject *parent = nullptr);
    class Private;
    QScopedPointer<Private> d;
};

}

#endif //UKUI_WORKSPACE_MANAGER_H