/*
 * profiles.h - deal with profiles
 * Copyright (C) 2001-2003  Justin Karneges
 *
 * 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 2
 * 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/>.
 *
 */

#ifndef PROFILES_H
#define PROFILES_H

#include "applicationinfo.h"
#include "common.h"
#include "iris/xmpp_clientstream.h"
#include "iris/xmpp_jid.h"
#include "iris/xmpp_roster.h"
#include "proxy.h"
#include "varlist.h"

#include <QByteArray>
#include <QList>
#include <QString>
#include <QStringList>
#include <QtCrypto>

class OptionsTree;

class UserAccount {
public:
    UserAccount();
    ~UserAccount();

    void reset();

    void fromOptions(OptionsTree *o, QString base);
    void toOptions(OptionsTree *o, QString base = QString());
    int  defaultPriority(const XMPP::Status &s);
    void saveLastStatus(OptionsTree *o, QString base);

    QString id;
    QString name;
    QString jid, pass, host, resource, authid, realm;
    QString scramSaltedHashPassword;
    bool    customAuth;
    bool    storeSaltedHashedPassword;
    quint16 port;
    int     priority;
    bool opt_enabled, opt_pass, opt_host, opt_auto, opt_keepAlive, opt_log, opt_connectAfterSleep, opt_autoSameStatus,
        opt_reconn, opt_ignoreSSLWarnings, opt_useProxyForUpload, opt_compress, opt_sm;

    bool                               req_mutual_auth;
    bool                               opt_automatic_resource, priority_dep_on_status, ignore_global_actions;
    XMPP::ClientStream::AllowPlainType allow_plain;
    int                                security_level;
    enum SSLFlag { TLS_No = 0, TLS_Yes = 1, TLS_Auto = 2, Direct_TLS = 3 } ssl;

    QString proxyID;

    XMPP::Roster roster;
    XMPP::Status lastStatus;
    bool         lastStatusWithPriority;

    struct GroupData {
        bool open;
        int  rank;
    };
    QMap<QString, GroupData> groupState;

    QString pgpSecretKey;

    VarList     pgpKnownKeys;
    QStringList pgpEnabledChats;
    QStringList pgpDisabledChats;

    XMPP::Jid dtProxy;
    bool      ibbOnly;

    QStringList alwaysVisibleContacts;
    QStringList localMucBookmarks, ignoreMucBookmarks;

    QString optionsBase;

    QStringList stunHosts;
    QString     stunHost;
    QString     stunUser;
    QString     stunPass;
    bool        onlyMyTurn = false;

    QByteArray tlsOverrideCert;
    QString    tlsOverrideDomain;

    /* migration only */
    int     proxy_index;
    int     proxy_type, proxy_port;
    QString proxy_host, proxy_user, proxy_pass;
    bool    tog_offline, tog_away, tog_agents, tog_hidden, tog_self;
};

typedef QList<UserAccount> UserAccountList;

class OptionsMigration {
public:
    void lateMigration();

    // QString progver;
    UserAccountList accMigration;

    ProxyItemList proxyMigration;

private:
    lateMigrationOptions lateMigrationData;
};

QString     pathToProfile(const QString &, ApplicationInfo::HomedirType type);
QString     pathToProfileConfig(const QString &);
QStringList getProfilesList();
bool        profileExists(const QString &);
bool        profileNew(const QString &);
bool        profileRename(const QString &, const QString &);
bool        profileDelete(const QStringList &);

extern QString activeProfile;

#endif // PROFILES_H
