#pragma once

#include <QWidget>

class QAbstractButton;

namespace Ui {
class SettingsWidget;
}

/**
 * @brief Server and logging settings
 */
struct ServerSettings {
    ServerSettings(); ///< Create structure with default setting values
    QString name; ///< Name on which server is listening
    bool logger; ///< True if logging into a log file is enabled
    bool systray; ///< True if minimizing into systray is enabled
};

/**
 * @brief Database access settings
 */
struct DatabaseSettings {
    DatabaseSettings();
    bool logging;
    QString hostname;
    QString database;
    QString username;
    QString password;
};

/**
 * @brief Application settings widget
 * Saving, loading and providing of configuration values
 */
class SettingsWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SettingsWidget(QWidget* parent = nullptr);
    void setSettingsFile(const QString& fileName);
    const ServerSettings& serverSettings() const;
    const DatabaseSettings& databaseSettings() const;
    ~SettingsWidget();

private slots:
    void onButtonToggled(QAbstractButton* button, bool checked);
    void saveSettings();
    void onTestConnectionPressed();

private:
    void connectServerSettings();
    void connectDatabaseSettings();
    void fillSettingsForms();

private:
    Ui::SettingsWidget* ui_;
    QString settingsFileName_;
    ServerSettings server_;
    DatabaseSettings database_;
};
