/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2025 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
 * the Free Software Foundation, either version 3 of the License, or
 * 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 <http://www.gnu.org/licenses/>.
 */

#ifndef DEVICEMANAGERWIDGET_H
#define DEVICEMANAGERWIDGET_H

#include <memory>
#include <unordered_map>

#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QStackedWidget>

#include "IDeviceManagerItem.h"
#include "DBusClient.h"
#include "BaseType.h"

using namespace UkuiAudioFramwork;

class DeviceManagerItem : public QFrame, public IDeviceManagerItem
{
public:
    DeviceManagerItem(QLabel*, std::shared_ptr<ISwitchButton>, const QString&, const QString&, QWidget* = nullptr);
    ~DeviceManagerItem() = default;

public:
    virtual bool isChecked() const override;

    virtual void setChecked(bool) override;

    virtual QWidget* getWidget() override;

    virtual std::shared_ptr<ISwitchButton> getSwitchBtn() const override;

    virtual QVariant getData() const override;

private:
    void initUi();

private:
    QString m_cardName;
    QString m_portName;
    QLabel* m_pLabel = nullptr;
    std::shared_ptr<ISwitchButton> m_pSwitchBtn = nullptr;
};

class DeviceManagerWidget : public QWidget
{
    Q_OBJECT
public:
    DeviceManagerWidget(QLabel*, QWidget* = nullptr);
    ~DeviceManagerWidget() = default;

public:
    void insertToWidget(int);

    void addItem(const QString&, const QString&, const QString&);

    void removeItem(int);

    void setChecked(int, bool);

    std::list<QVariant> getDataList() const;

Q_SIGNALS:
    void enableDeviceSignals(const QString&, const QString&, bool);

    void closeWindowSignals();

private:
    void initUi();

    void initSlots();

private Q_SLOTS:
    void closeWindow();

private:
    QLabel* m_pLabel = nullptr;
    QScrollArea* m_pScrollArea = nullptr;
    QWidget* m_pDisDevManagerWidget = nullptr;
    QVBoxLayout* m_pVlayout = nullptr;
    QPushButton* m_pConfirmBtn;
    QStackedWidget* m_pStackWidget;
    std::vector<std::shared_ptr<IDeviceManagerItem>> m_devManagerItemVec {};
//    std::unordered_map<int, std::shared_ptr<IDeviceManagerItem>> m_devManagerItemMap {};
    NodeType m_type;
};

#endif // DEVICEMANAGERWIDGET_H
