function logResponseToConsole(res) {
  var status = res.status;

  if (status !== 200) {
    console.log("ERRORE HTTP! Response status code: " + status);
    return;
  }

  var decodedDocument = "";
  var response = res.getBody();

  if (response.value.code === "ERROR") {
    decodedDocument = "ERRORE EFTL!\n";
    decodedDocument += response.value.description.split("\n").slice(0, 3).join("\n");
  }
  else {
    decodedDocument = atob(response.value.processedDocument);
  }
  response.decodedDocument = decodedDocument;

  console.log(response.decodedDocument);
}

function prepareEftlDocument(doc) {
  bru.setVar("elixBase64EftlDocument", btoa(doc));
}

module.exports = {
  logResponseToConsole,
  prepareEftlDocument
};
