#include "connectortoserver.h"

bool ConnectorToServer::sendAuthorizationInstructorLocal(QString login, QString password)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    ClientAutorization *autorization = new ClientAutorization;
    autorization->Login = login;
    autorization->Password = password;
    autorization->TypeClient = TypeClientAutorization::TYPE_GUI;

    QByteArray array = dataParser->createAuthMessage(autorization);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendDeAuthorizationInstructorLocal(QString login)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    ClientDeAutorization *deAutorization = new ClientDeAutorization;
    deAutorization->Login = login;

    QByteArray array = dataParser->createDeAuthMessage(deAutorization);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery, int id, void* data)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    ClientQueryToDB *queryToDB = new ClientQueryToDB;
    queryToDB->typeQuery = typeQuery;

    QByteArray array = dataParser->createQueryToDBMessage(queryToDB, id, data);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendMessage(ClientMessage clientMessage)
{
    if (!client->getIsConnected())
    {
        return false;
    }
    QByteArray array = dataParser->createMessage(clientMessage);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendClientNotify(QString command)
{
    QByteArray answer = dataParser->xmlAnswer_notify(command);
    emit sigSendAnswerToServer(answer);
    return true;
}

bool ConnectorToServer::sendQueryTasksXML(QString type)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    QByteArray array = dataParser->createQueryTasksXMLMessage(type);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendQueryListSubProc(QString dmCode)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    QByteArray array = dataParser->createQueryListSubProcMessage(dmCode);
    emit sigSendAnswerToServer(array);

    return true;
}

bool ConnectorToServer::sendQueryBlockAuth(bool block)
{
    if (!client->getIsConnected())
    {
        return false;
    }

    QByteArray array = dataParser->createQueryBlockAuth(block);
    emit sigSendAnswerToServer(array);

    return true;
}

void ConnectorToServer::sendShowVersionSelect()
{
    QByteArray answer = dataParser->xmlAnswer_notify(cmd_CheckVersionList);
    emit sigSendAnswerToServer(answer);
}
