/*
 * Copyright (C) 2023 Tianjin KYLIN Information Technology 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, 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 <http://www.gnu.org/licenses/>.
 *
**/
#include "userinfo.h"
#include "global_utils.h"

UserInfo::UserInfo()
    : m_isLoggedIn(false)
    , m_uId(-1)
    , m_strBackground(DEFAULT_BACKGROUND_PATH)
    , m_strLang(qgetenv("LANG"))
    , m_strName("")
{
    m_strHeadImage = getDefaultFace();
}

UserInfo::UserInfo(const UserInfo &userInfo)
    : m_isLoggedIn(userInfo.m_isLoggedIn)
    , m_uId(userInfo.m_uId)
    , m_strHeadImage(userInfo.m_strHeadImage)
    , m_strFullName(userInfo.m_strFullName)
    , m_strBackground(userInfo.m_strBackground)
    , m_strLang(userInfo.m_strLang)
    , m_strName(userInfo.m_strName)
{

}

UserInfo::~UserInfo()
{

}

bool UserInfo::operator==(const UserInfo &userInfo) const
{
    return userInfo.uid() == m_uId && userInfo.name() == m_strName;
}

UserInfo& UserInfo::operator=(const UserInfo &userInfo)
{
    if (this == &userInfo) return *this;

    updateLoggedIn(userInfo.isLoggedIn());
    updateUid(userInfo.uid());
    updateHeadImage(userInfo.headImage());
    updateFullName(userInfo.fullName());
    updateBackground(userInfo.backGround());
    updateLang(userInfo.lang());
    updateName(userInfo.name());
    return *this;
}

void UserInfo::updateLoggedIn(const bool &isLoggedIn)
{
    m_isLoggedIn = isLoggedIn;
}

void UserInfo::updateUid(const uid_t &id)
{
    m_uId = id;
}

void UserInfo::updateHeadImage(const QString &path)
{
    m_strHeadImage = path;
}

void UserInfo::updateFullName(const QString &fullName)
{
    m_strFullName = fullName;
}

void UserInfo::updateBackground(const QString &backGround)
{
    m_strBackground = backGround;
}

void UserInfo::updateLang(const QString &lang)
{
    m_strLang = lang;
}

void UserInfo::updateName(const QString &name)
{
    m_strName = name;
}

QDebug operator <<(QDebug stream, const UserInfo &userInfo)
{
    stream << "["
           << userInfo.uid()
           << userInfo.name()
           << userInfo.fullName()
           << userInfo.headImage()
           << userInfo.backGround()
           << userInfo.isLoggedIn()
           << userInfo.lang()
           << "]";
    return stream;
}
