/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2024 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
 * 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 POWER_H
#define POWER_H

#include <QDBusContext>
#include <QObject>

enum UpDeviceType
{
    UP_DEVICE_TYPE_UNKNOWN = 0,
    UP_DEVICE_TYPE_LINE_POWER,
    UP_DEVICE_TYPE_BATTERY,
    UP_DEVICE_TYPE_UPS,
    UP_DEVICE_TYPE_MONITOR,
    UP_DEVICE_TYPE_MOUSE,
    UP_DEVICE_TYPE_KEYBOARD,
    UP_DEVICE_TYPE_PDA,
    UP_DEVICE_TYPE_PHONE,
    UP_DEVICE_TYPE_MEDIA_PLAYER,
    UP_DEVICE_TYPE_TABLET,
    UP_DEVICE_TYPE_COMPUTER,
    UP_DEVICE_TYPE_MAX    
};


class UkuiPowerInterface : public QObject, protected QDBusContext
{
    Q_OBJECT

    Q_CLASSINFO("D-Bus Interface", "org.ukui.Framework.Devices.Power")

public:
    explicit UkuiPowerInterface(QObject *parent = nullptr);
    ~UkuiPowerInterface() override;

public slots:
    /**
     * @brief getPowerSaveLevel 获取节能等级
     * @return  -1:错误信息； 0：正常工作； 1：节能； 2：极低电量
     */
    int GetPowerSaveLevel();

    /**
     * @brief getPowerMode 获取电源工作模式
     * @return  -1:错误信息； 0：性能； 1：平衡； 2：节能
     */
    int GetPowerMode();

    /**
     * @brief SetPowerMode
     * @param mode 0:性能模式 1：平衡模式  2：能效模式
     */
    void SetPowerMode(uint mode);

    /**
     * @brief batteryPercentage 获取电量百分比
     * @return -1:错误信息；1-100：电量百分比
     */
    int BatteryPercentage();

    /**
     * @brief timeToFull 获取充满电时间
     * @return -1:错误信息；获取充满电时间 单位：秒；
     */
    int TimeToFull();

    /**
     * @brief timeToUse 获取可用时长
     * @return -1:错误信息；可用时长 单位：秒
     */
    int TimeToEmpty();

    /**
     * @brief getBatteryState 获取电池状态
     * @return
     * -1:错误信息； 0：未知状态 1：充电状态 2：放电状态 3：电量为空 4：电池已充满 5：准备充电 6：准备断开充电
     */
    int GetBatteryState();

    /**
     * @brief isBatteryPresent 是否有电池接入
     * @return true:有电池接入；false:无电池接入
     */
    bool IsBatteryPresent();

    /**
     * @brief isLid 是否有盖子
     * @return true:有盖子；false:无盖子
     */
    bool IsLid();

    void onDeviceAdded(const QString &devicePath);

    void onDeviceRemoved(const QString &devicePath);

private:
    void getBatteryDbusPath();
    QVariant getBatteryProperty(const QString &propertyName);
    int getDeviceType(const QString &dBusPath);

    QString m_batteryPath;
};


#endif // POWER_H
