#ifndef AREAINTERFACE_H
#define AREAINTERFACE_H

#include <ukui-service-interface/serviceobject.h>
#include <QtDBus>
#include "../../universalinterface.h"
#include <kysdk/kysdk-system/libkysysinfo.h>

class AreaInterface : public UKUI::ServiceObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.ukui.ukcc.session.Area")
    Q_PROPERTY(QStringList formatCountryList READ getFormatCountryList)
    Q_PROPERTY(QStringList calendarList READ getCalendarList)
    Q_PROPERTY(QStringList firstDayList READ getFirstDayList)
    Q_PROPERTY(QStringList dateFormatList READ getDateFormatList)
    Q_PROPERTY(QStringList timeFormatList READ getTimeFormatList)
    Q_PROPERTY(QStringList languageList READ getLanguageList)
    Q_PROPERTY(QStringList showLanguageList READ getShowLanguageList)
    Q_PROPERTY(QString formatCountry READ getFormatCountry)
    Q_PROPERTY(QString calendar READ getCalendar)
    Q_PROPERTY(QString firstDay READ getFirstDay)
    Q_PROPERTY(QString dateFormat READ getDateFormat)
    Q_PROPERTY(QString timeFormat READ getTimeFormat)
    Q_PROPERTY(QString language READ getLanguage)
    Q_PROPERTY(QString lunarDate READ getLunarDate)

public:
     AreaInterface();
    ~AreaInterface();
    void initConnect();

protected:
    // 对属性的访问函数
    QStringList getFormatCountryList();
    QStringList getCalendarList();
    QStringList getFirstDayList();
    QStringList getDateFormatList();
    QStringList getTimeFormatList();
    QStringList getLanguageList();
    QStringList getShowLanguageList();
    QString getFormatCountry();
    QString getCalendar();
    QString getFirstDay();
    QString getDateFormat();
    QString getTimeFormat();
    QString getLanguage();
    QString getLunarDate();
    bool isOpenkylin();

public Q_SLOTS:
    /**
     * @brief 修改输入法
     *
     * @param inputMethodName 输入法名称
     * @param add 添加/移除
     */
    void changeInputMethod(const QString &inputMethod, const bool &add);

    /**
     * @brief 查询输入法是否已经添加
     *
     * @param inputMethodName 输入法名称
     * @return bool 返回输入法是否已经添加
     */
    bool isAddedInputMethod(const QString &inputMethod);

    // 对属性的设置函数
    void setFormatCountry(const QString &formatCountry);
    void setCalendar(const QString &calendar);
    void setFirstDay(const QString &firstDay);
    void setDateFormat(const QString &dateFormat);
    void setTimeFormat(const QString &timeFormat);
    void setShowLanguageList(const QStringList &languageList);
    void setLanguage(const QString &languageCode);

Q_SIGNALS:
    void changed(QString keyName);

private:
    void reloadInputMethodConfig();

    // 设置和获取gsetting的string类型的键值
    QString gsettingGet(const QString &key) const;
    void gsettingSet(const QString &key, const QString &value);
    QString gsettingCalendarGet(const QString &key) const;

private:
    const QString SHOW_LANGUAGE_KEY = QString("showlanguage");
    const QString FCITX_CONFIG_FILE = QDir::homePath() + "/.config/fcitx/profile";
    const QString CALENDAR_KEY      = QString("calendar");
    const QString FIRST_DAY_KEY     = QString("firstday");
    const QString DATE_FORMATE_KEY  = QString("date");
    const QString TIME_FORMAT_KEY   = QString("hoursystem");
    const QString LUNAR_DATE_KEY    = QString("lunarDate");

private:
    QGSettings     *ukccPanelGsettings = nullptr;
    QDBusInterface *accountInterface   = nullptr;
    QDBusInterface *fcitxInterface     = nullptr;
    QGSettings     *styleGsettings     = nullptr;
    QGSettings      *m_calendarGsettings = nullptr;
};

#endif // AREAINTERFACE_H
