#include "account.h"

Account::Account(int id, const QString& email, const QString& displayName,
                 const QString& signature,
                 AccountType type, const QString& accessToken,
                 const QString& refreshToken,
                 const QDateTime& tokenExpires)
    : m_id(id)
    , m_email(email)
    , m_displayName(displayName)
    , m_signature(signature)
    , m_type(type)
    , m_accessToken(accessToken)
    , m_refreshToken(refreshToken)
    , m_tokenExpires(tokenExpires)
{
}

QString Account::encryptPassword(const QString& plainText)
{
    // Simple XOR encryption with a fixed key, then base64 encode
    // Note: This is for obfuscation only, not strong security.
    static const char keyHex[] = "0123456789ABCDEF"; // 16-byte key
    QByteArray key;
    bool ok;
    for (int i = 0; i < 16; ++i) {
        char c = QString::fromLatin1(keyHex + i * 2, 2).toInt(&ok, 16);
        if (!ok) c = 0;
        key.append(c);
    }

    QByteArray input = plainText.toUtf8();
    QByteArray result(input.size(), 0);
    for (int i = 0; i < input.size(); ++i) {
        result[i] = input[i] ^ key[i % key.size()];
    }
    return result.toBase64();
}

QString Account::decryptPassword(const QString& encrypted)
{
    // Same as encryption since XOR is symmetric
    return encryptPassword(encrypted);
}
