#include "loginapi.h"

#include <QJsonDocument>
#include <QJsonObject>

namespace AuthApi {
QFuture<HttpResponse> loginApi(const LoginParams& data)
{
    QJsonObject jsonData;
    jsonData["username"] = data.username;
    jsonData["password"] = data.password;
    jsonData["captchaId"] = "testtesttesttesttest";
    jsonData["captcha"] = "testa";

    QJsonDocument doc(jsonData);

    return TC::RequestClient::globalInstance()->postAsync("/user/login", doc);
}

QFuture<HttpResponse> refreshTokenApi()
{
    QJsonObject config;
    config["withCredentials"] = true;
    QJsonDocument doc(config);

    return TC::RequestClient::globalInstance()->postAsync("/auth/refresh", doc);
}

QFuture<HttpResponse> logoutApi()
{
    QJsonObject config;
    config["withCredentials"] = true;
    QJsonDocument doc(config);

    return TC::RequestClient::globalInstance()->postAsync("/user/logout", doc);
}

QFuture<HttpResponse> getAccessCodesApi()
{
    return TC::RequestClient::globalInstance()->getAsync("/user/perm");
}

} // namespace AuthApi
