#include "Question.h"

Question::Question(int id, std::string text, std::string correct_answer, int score)
{
    this->_id = id;
    this->_text = text;
    this->_correct_answer = correct_answer;
    this->_score = score;
}

Question::Question()
{
    this->_id = -1;
    this->_text = "";
    this->_correct_answer = "";
    this->_score = -1;
}

int Question::id()
{
    return this->_id;
}

std::string Question::text()
{
    return this->_text;
}

std::string Question::correct_answer()
{
    return this->_correct_answer;
}

int Question::score()
{
    return this->_score;
}

void Question::id(int id)
{
    this->_id = id;
}

void Question::text(std::string text)
{
    this->_text = text;
}

void Question::correct_answer(std::string correct_answer)
{
    this->_correct_answer = correct_answer;
}

void Question::score(int score)
{
    this->_score = score;
}

void operator>>(std::string& is, Question& q)
{
    std::string buffer;
    buffer = is.substr(0, is.find(","));
    q.id(std::stoi(buffer));
    is.erase(0, is.find(",") + 1);
    buffer = is.substr(0, is.find(","));
    q.text(buffer);
    is.erase(0, is.find(",") + 1);
    buffer = is.substr(0, is.find(","));
    q.correct_answer(buffer);
    is.erase(0, is.find(",") + 1);
    buffer = is;
    q.score(std::stoi(buffer));
}

std::ofstream& operator<<(std::ofstream& os, Question& q)
{
    os << q.id() << "," << q.text() << "," << q.correct_answer() << "," << q.score() << "\n";
    return os;
}